Skip to content

Instantly share code, notes, and snippets.

@ak2766
Created February 16, 2020 03:59
Show Gist options
  • Save ak2766/76b062ef050642cf1c9934031f499926 to your computer and use it in GitHub Desktop.
Save ak2766/76b062ef050642cf1c9934031f499926 to your computer and use it in GitHub Desktop.
void main() {
print(getTimeInISO8601());
}
String getTimeInISO8601() {
var ct = DateTime.now().toUtc();
String year = ct.year.toString().padLeft(4,'0');
String month = ct.month.toString().padLeft(2,'0');
String day = ct.day.toString().padLeft(2,'0');
String hour = ct.hour.toString().padLeft(2,'0');
String min = ct.minute.toString().padLeft(2,'0');
String sec = ct.second.toString().padLeft(2,'0');
String timeUTC = '$year-$month-${day}T$hour:$min:${sec}Z';
return timeUTC;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment