Timezone conversion for the Time Input widget

Dear friends,
as I saw, using the Time Input widget, the variable getTZ() keeps the selected timezone but in string like: “Europe/Athens”. Is there an easy way to convert it in time difference from UTC? (ex in case of Europe/Athens this will be UTC +3)

Thanks and Best Regards,
Mike Kranidis

I have noticed that there is a selection for Nicosia in Asia and in Europe.

Currently using the European destination.

@mikekgr I guess the String representation is why my timezone has stopped working.

Serial.println(String("Time zone: ") + time_input.getTZ()); gives zero rather than 3.

So what do you suggest?
It is strange that the Time Input widget does not provide timezones as a numeric displacement from UTC. Am I right @Dmitriy to this conclusion or I missed something?


Yes you are right and as a minimum we need a “look up table” for String to UTC conversion.


Thanks @Costas

@Dmitriy what is the fix for RTC now providing Strings rather than UTC seconds?

@Costas correct :slight_smile:.

@Dmitriy but RTC is now “broken” as we don’t know how to convert the Strings you are providing to a usable UTC.

Get the TimeZone library and stay on using UNIX times, it’s the only viable solution for now (that I’m aware off). The TimeZone library converts times to/from UTC/local. Once you get the hang of it, it works really well.

Ow yes, the TimeZone lib also supports (custom) DST!

1 Like

@Lichtsignaal although another library would solve the problem I don’t really think that is the fix.

We are already providing the offset in the RTC and TimeInput widgets so the solution should be based around this.

Agreed, but for now I find it the most elegant solution to have Blynk do everything in UTC and I make my own times, with or without DST. Using a workaround is never a fix of course :slight_smile:

It should be based on the clock of the phone, which will do everything correct if setup ok. It knows the location of the user and it’s timezones.

I could be wrong but I don’t think Blynk has access to phone time.
Is it a problem for you if @Dmitriy makes TimeInput work to local time rather than UTC?

Not really, I wouldn’t mind either way, but it has to be clear how it works. I do an API call to get, for example, sunrise/sunset times from a website and they are all in UTC, so for me personally it’s easier if everything is UTC. I can do my own calculations based on that (and that’s how I’ve set it up right now). The Wemos handles it fine so far :wink:

Just checking, but I convert the currentTime for measurements at only one point, so using local time from RTC widget instead of UTC saves me 1 line of code :smiley:

@mikekgr @Costas could you please test this build and tell me if that what you expect? You need to select at least 1 day to make it work (server issue). startTime/endTime now in local time of selected timezone. Offset also available if needed.

Waiting for your feedback.

yes for sure.
I will let you know the soonest!

Dear @Dmitriy ,
the Android app you sent us is working fine but in the Arduino sketch I can not use the new time zone offset variable (I suppose that an updated library it is mandatory). I get the folowing error:
class TimeInputParam’ has no member named 'getTZ_Offset

Please comment.

You are right. Sorry I forgot to mention that.

1 Like

@Dmitriy thanks I can confirm TimeInput now gives the times as local.

Serial.println(String("Time zone offset: ") + t.getTZ_Offset()); is coming back with this error:

'class TimeInputParam' has no member named 'getTZ_Offset'

Will 0.3.9 that @vshymanskyy published earlier tonight include getTZ_Offset ?
And t.getTZ() is compiling but giving a value of zero, is this covered by 0.3.9 as well or do we need to remove the widget and set the TZ again?

Yes. We just did this change few hours ago.

TZ should be there.

It is there but Serial.println(String("Time zone: ") + t.getTZ()) gives 0 rather than the 3 I expect for Nicosia.
I have removed TimeInput widget and added in again but same result.
I assume I don’t need to remove RTC as TimeInput has it’s own TZ setting.