Time Tags and UTC

51 views
Skip to first unread message

Eric Mears

unread,
May 16, 2019, 6:48:11 PM5/16/19
to weewx-user
Hi,

I'm running weewx on a raspberry pi connected to a Vantage weather station.

I create a custom report that that National Weather Service downloads hourly.

The National Weather Service requires the times be in UTC.


I'd like to run my raspberry pi on local time so the weewx reports display local time.

Is there an option on a Time Tag to display UTC?

I'm currently using variations of 

$current.dateTime.format("%H:%M %Z")

in my custom report, but these all display local time.


Do I have any options other than running the raspberry pi on UTC?

Thanks,

Eric




p q

unread,
May 16, 2019, 6:54:13 PM5/16/19
to weewx-user
I imagine your Raspberry Pi is using UTC as its base time and using the time zone to display the local time. That's the standard way it's set up.

I haven't tried it but you might be able to use the python function datetime.utcnow() https://docs.python.org/3/library/datetime.html#datetime.datetime.utcnow

gjr80

unread,
May 16, 2019, 7:23:29 PM5/16/19
to weewx-user
Hi,

It was a deliberate decision for WeeWX to be timezone unaware, but fortunately we can do some limited utc manipulation using some of the inbuilt utc capabilities of the python datetime module. In this case the easiest approach is likely just putting a little inline python code in your template. Something like:

#import datetime
#set $local_dt = datetime.datetime.utcfromtimestamp($current.dateTime.raw)
#set $utc_formatted = $local_dt.strftime("%d/%m/%Y %H:%M:%S")

and then when you want to display the utc time just use the $utc_formatted tag in your template, something like:

The current time is: $current.dateTime (local) or $utc_formatted (UTC)

would give something like:

The current time is: 17/05/19 09:18:00 (local) or 16/05/2019 23:18:00 (UTC)

The only requirement is the code needs to be included at a location in the template before the tag is used. The format of the output can be changed by using the format codes from here. You could go to more trouble and create a tag (or an SLE that returns a tag) that accepts the format string as a parameter but given your intended use this is the simplest approach.

Gary

Eric Mears

unread,
May 16, 2019, 7:23:56 PM5/16/19
to weewx-user
Hi Peter,

I was looking at 

but I couldn't figure out how to call it from the tag.

I'm still a newbie at this.

Thanks,

Eric

Eric Mears

unread,
May 16, 2019, 7:25:20 PM5/16/19
to weewx-user
Gary,

Thanks,

I will give that a try.

Eric

Leon Shaner

unread,
May 16, 2019, 7:43:59 PM5/16/19
to weewx...@googlegroups.com
We're all fine with the timestamps until 2038.  ;-)

https://en.m.wikipedia.org/wiki/Year_2038_problem

Regards,
\Leon
--
Leon Shaner :: Dearborn, Michigan (iPad Pro)
--
You received this message because you are subscribed to the Google Groups "weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to weewx-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-user/af9ae8c1-a26a-4ee3-a305-63f83d439fcc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages