How do I convert my current time into GMT/ UTC time in Dart, similar to the javascript way: new Date().toUTCString()
:
Tue, 01 Nov 2011 19:06:35 GMT
I tried couple of formatters see below but it did not work
//var f = DateFormat('E, d MMM yyyy HH:mm:ss z');
var f = DateFormat('E, d MMM yyyy HH:mm:ss');
var date = f.format(DateTime.now());
Convert your current time to UTC and append
" GMT"
to the string.Using an arbitrary timezone (not just GMT/ UTC)
Although it is in the documentation, you can't create strings with arbitrary timezones with DateTime, as timezone support/ implementation has been missing, and is a GitHub issue since 2015. For example, you can't display a different timezone in the string, as using
z
in the format string doesn't work: callers get anUnimplementedError
. See the 3 related GitHub issues: one, two and three.