Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. void main() {
  2.  
  3. print(converteDataPadrao(DateTime.now().toUtc()));
  4. print(converteDataPadrao(DateTime.now()));
  5.  
  6. }
  7.  
  8.  
  9. String converteDataPadrao(DateTime data) {
  10.  
  11. if (data.isUtc) data = data.toLocal();
  12. var utcString = data.toIso8601String().substring(0, 19);
  13. var timeZoneString = data.timeZoneOffset.toString();
  14. return "$utcString${ajustaTimeZone(timeZoneString)}";
  15. }
  16.  
  17. String ajustaTimeZone(String timezone){
  18. final splitado = timezone.split(':');
  19. if(splitado[0].length != 3){
  20. final splitado1 = splitado[0].split('');
  21. splitado[0] = "${splitado1[0]}${splitado1[1].padLeft(2,'0')}";
  22. }
  23. return "${splitado[0]}:${splitado[1]}";
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement