DateTime Date Conversion in Flutter Learning

Keywords: Python less


First, the method is detailed.

  • Naming constructs to get the current time
    now()
  • DateTime timestamp
    millisecondsSinceEpoch
  • Timestamp Transfer DateTime
    fromMillisecondsSinceEpoch
  • String Rotation DateTime
    parse(string)
  • Time comparison - before
    isBefore(date)
  • Time comparison - after
    isAfter(date)
  • Time comparison - equality
    isAtSameMomentAs(date)
  • Greater than return 1; equal to return 0; less than Return-1
    compareTo(date)
  • Time increases
    add(Duration)
  • Time reduction
    subtract(Duration)
  • Hours of difference between two times
    difference(date)
  • Simplified local time zone code
    timeZoneName
  • Return UTC and Hours of Local Time Difference
    timeZoneOffset
  • Return years, months, days, hours, minutes, seconds, milliseconds, subtleties
    year,month,day,hour,minute,second,millisecond,microsecond
  • Return to Wednesday
    weekday

2. Conversion between strings and dates

  • String-->DateTime:
    DateTime.parse(String);
  • DateTime -->formatString:
    formatDate(DateTime ,[yyyy,'-',mm,'-',dd]);


Three, code examples

var today = DateTime.now();
print('The current time is: $today');
var date1 = today.millisecondsSinceEpoch;
print('Current timestamp: $date1');
var date2 = DateTime.fromMillisecondsSinceEpoch(date1);
print('Time stamp date: $date2');
//Stitching date
var dentistAppointment = new DateTime(2019, 6, 20, 17, 30,20);
print(dentistAppointment);
// String Conversion date
DateTime date3 = DateTime.parse("2019-06-20 15:32:41");
print(date3);
// Time comparison
print(today.isBefore(date3));// Before
print(today.isAfter(date3)); // After that
print(date3.isAtSameMomentAs(date3));// identical

print(date3.compareTo(today));// Greater than return 1; equal to return 0; less than return-1. 
// print(DateTime.now().toString());
// print(DateTime.now().toIso8601String());

//Time increases
var fiftyDaysFromNow = today.add(new Duration(days: 5));
print('today Add 5 days: $fiftyDaysFromNow');
//Time reduction
DateTime fiftyDaysAgo = today.subtract(new Duration(days: 5));
print('today Less 5 days: $fiftyDaysAgo');
//Hours of difference between two times
print('Compare two hours of time difference: ${fiftyDaysFromNow.difference(fiftyDaysAgo)}');

print('Simplified code for local time zone: ${today.timeZoneName}');

print('Return UTC Hours with local time difference: ${today.timeZoneOffset}');

print('Acquisition year, month and day: ${today.year}');//month,day,hour,minute,second,millisecond,microsecond

print('Weekly: ${today.weekday}');// Return to Wednesday

Fourth, example results

Posted by cullouch on Tue, 30 Jul 2019 19:35:18 -0700