I'm receiving a DateTime
response from API that's sets the timezone to UTC.
But when I try to convert the received data using toLocal()
it doesn't convert.
my local time is HKT
here's my code.
//TIME DIFFERENCE
getNotificationDate(DateTime date) {
date = date.toUtc();
final convertedDate = date.toLocal();
final dateNow = DateTime.now();
print('TIMENOW: ' + dateNow.toString());
print('TIMENOTIFC: ' + convertedDate.toString());
final difference = dateNow.difference(convertedDate);
print('DIFFERENCE: ' + difference.toString());
return getDurationFormat(difference);
}
EDIT:
date
is the DateTime
I'm receiving from the API. which is in UTC timezone.
I used print('TIMEZONENAME: ' + date.timeZoneName;
and it automatically sets the timezone to HKT. that's why it does nothing when I try to use date.toLocal()