Open Nissimarcus11 opened 3 years ago
try{
// make the request
Response response = await get('http://worldtimeapi.org/api/timezone/$url');
Map data = jsonDecode(response.body);
// get properties from json
String datetime = data['datetime'];
String offset = data['utc_offset'].substring(1,3);
String sign = data['utc_offset'].substring(0,1);
print("sign is $sign");
// create DateTime object
DateTime now = DateTime.parse(datetime);
now = sign == '+'? now.add(Duration(hours: int.parse(offset))):now.subtract(Duration(hours: int.parse(offset)));
// set the time property
isDaytime = now.hour > 6 && now.hour < 20 ? true : false;
time = DateFormat.jm().format(now);
}
Add ternary operator to read UTC value and add/substract based on that
Showing wrong time for New York