Skip to main content

Hello FME Community!

 

I'm having trouble transforming a datetime to incorporate ​a UTC offset. Using the DateTimeConverter, any time I try to use the Timezone shortcuts (%z or %Ez), it tells me "Output Formatting Error: format flag '%z' is not supported for input type 'datetime' in the Preview Data window. I've read the transformer specifics and date/time terminology, etc. I've also tried using a DateTimeCalculator to use @TimeZoneSet but can't figure out the syntax there either. I've attached two screenshots - the first is what I want to resolve the datetime format to (but had no UTC offset) and the second is when I use the Timezone UTC offset shortcut.

 

I'm sure I'm missing something in the syntax - can someone help?

 

Thanks!

Use @TimeZoneSet in an AttributeCreator, e.g.

CaptureYou can then wrap that with the DateTimeFormat statement (or just follow up with a DateTimeConverter)

@DateTimeFormat(@TimeZoneSet(@Value(time),utc),%Y-%m-%dT%T%z)

 


Thank you @ebygomm​ 

This all worked, however I don't understand the actual offset, it's showing +00:00. This may just be my ignorance to do with changing timezones, but, as an example, how do I go about offsetting 2016-01-28T16:22:04 (which is in Eastern Standard Time) to UTC? Can you feed the expression the timezone to convert FROM? At present EST vs UTC is +4:00 hours, but at times of the year it will be +5:00 hours (daylight savings time).

How would I convert 2016-01-28T16:22:04+00:00 to 2016-01-28T20:22:04? I'm looking to show the latter. I know I can use the DateTimeCalculator to just add 4 hours to the incoming datetime attribute, but this wouldn't always be correct with daylight savings time (half the year +4 hours, half the year +5 hours).

Any thoughts on this?

Thanks


Thank you @ebygomm​ 

This all worked, however I don't understand the actual offset, it's showing +00:00. This may just be my ignorance to do with changing timezones, but, as an example, how do I go about offsetting 2016-01-28T16:22:04 (which is in Eastern Standard Time) to UTC? Can you feed the expression the timezone to convert FROM? At present EST vs UTC is +4:00 hours, but at times of the year it will be +5:00 hours (daylight savings time).

How would I convert 2016-01-28T16:22:04+00:00 to 2016-01-28T20:22:04? I'm looking to show the latter. I know I can use the DateTimeCalculator to just add 4 hours to the incoming datetime attribute, but this wouldn't always be correct with daylight savings time (half the year +4 hours, half the year +5 hours).

Any thoughts on this?

Thanks

Ah, i hadn't understood that your times were in Eastern Standard Time and you want to convert to UTC.

 

As long as the machine you are working on has its time set to Eastern Standard Time you can do this

@TimeZoneSet(@TimeZoneSet(@Value(date),local),utc,convert)

This will add the Eastern Standard Time offset to your datetime (4 or 5 hours depending on the date) and then convert it to a utc datetime which you can then format however you need

 

It's hard to demonstrate, since I'm in the wrong timezone but hopefully this might help

 

CaptureThe inner TimeZoneSet adds the timezone based on your machine settings, so in my case a date of 12 Feb gets +00:00 whilst 12th June gets +1:00 (date_with_timezone). In your case, this would get -5:00 and -4:00. The outer TimeZoneSet then applies the offset to the time (utc_date). So in my case this subtracts an hour for the June datetime. 


Ah, i hadn't understood that your times were in Eastern Standard Time and you want to convert to UTC.

 

As long as the machine you are working on has its time set to Eastern Standard Time you can do this

@TimeZoneSet(@TimeZoneSet(@Value(date),local),utc,convert)

This will add the Eastern Standard Time offset to your datetime (4 or 5 hours depending on the date) and then convert it to a utc datetime which you can then format however you need

 

It's hard to demonstrate, since I'm in the wrong timezone but hopefully this might help

 

CaptureThe inner TimeZoneSet adds the timezone based on your machine settings, so in my case a date of 12 Feb gets +00:00 whilst 12th June gets +1:00 (date_with_timezone). In your case, this would get -5:00 and -4:00. The outer TimeZoneSet then applies the offset to the time (utc_date). So in my case this subtracts an hour for the June datetime. 

​Thanks @ebygomm​ , that's exactly what I was looking for!


Reply