Home > Mobile >  How to add 24 hours to a millisecondsSinceEpoch time in flutter?
How to add 24 hours to a millisecondsSinceEpoch time in flutter?

Time:10-19

I need to add 24 hr on selected date slot in calendar in millisecondsSinceEpoch. As in the below code if I add 24 hr it will give me 00:00 time for same day so I tried to use this (23,minutes: 59,seconds: 59) which is wrong. Please suggest....

    DateTime initialTime = selectedDate.value;
    DateTime finalTime = selectedDate.value.add(new Duration(hours: 23,minutes: 59,seconds: 59));
    
    int finalTimeInEpoch = finalTime.millisecondsSinceEpoch;
    print('This is the initial time for selected day --> $initialTime and This is the final time for selected day --> $finalTime');
    int initialTimeForApi = initialTime.millisecondsSinceEpoch;
    int  finalTimeForApi= finalTimeInEpoch;
    print('This is the initial time for selected day --> ${initialTime.millisecondsSinceEpoch} and This is the final time for selected day --> $finalTimeInEpoch in millisecondsSinceEpoch');
   

CodePudding user response:

Use Like This

DateTime finalTime = selectedDate.value.add(Duration(hours: 24));

if this don fix the issue your problem is selectedDate.value is not a valid format date time

  • Related