[resolved] Get UTC date

Seven Stars

[resolved] Get UTC date

Please could someone tell me the easiest way to get the current UTC time in the format yyyy-MM-dd HH:mm:ss.SSS. I can't for the life of me figure it out for some reason.

Accepted Solutions
One Star

Re: [resolved] Get UTC date

For reference, it is easier and better to use TalendDate.formatDateInUTC
TalendDate.formatDateInUTC("yyyy-MM-dd HH:mm:ss", TalendDate.getCurrentDate() )

All Replies
One Star

Re: [resolved] Get UTC date

Do you want to convert a time zone to GMT?
From Wikipedia
Time zones are usually defined to differ from UTC by an integer number of hours, although the laws of each jurisdiction would have to be consulted if sub-second accuracy was required. Several jurisdictions have established time zones that differ by an integer number of half-hours or quarter-hours from UT1 or UTC.
The UTC time zone is sometimes denoted by the letter Z?a reference to the equivalent nautical time zone (GMT), which has been denoted by a Z since about 1950.
Seven Stars

Re: [resolved] Get UTC date

Yes, I suppose. I want the equivalent of TalendDate.getDate("yyyy-MM-dd HH:mm:ss.SSS") but where the result is the time in UTC rather than my default timezone i.e. if I call the expression at 11pm in my +10 timezone then the result would be "2012-08-02 13:00:00.000" and needs to factor in local DST when applicable.
One Star

Re: [resolved] Get UTC date

Found this on the web. It's a web service for UTC time.
http://www.nanonull.com/TimeService/TimeService.asmx?op=getOffesetUTCTime
There's also a getUTCTime.
Seven Stars

Re: [resolved] Get UTC date

Surely there's a way to do it with Java?
Seven Stars

Re: [resolved] Get UTC date

I did it like this, which seems to work, including accounting for daylight saving
Calendar c = Calendar.getInstance();
TimeZone tz = c.getTimeZone();
Long ms = c.getTimeInMillis();
Date dt = new Date(ms-tz.getOffset(ms));

Note that c.getTime() always gives local time, even if c is instantiated with a different TimeZone.
One Star

Re: [resolved] Get UTC date

For reference, it is easier and better to use TalendDate.formatDateInUTC
TalendDate.formatDateInUTC("yyyy-MM-dd HH:mm:ss", TalendDate.getCurrentDate() )
Seven Stars

Re: [resolved] Get UTC date

Which was added in v6.0.1.

Calling Talend Open Studio Users

The first 100 community members completing the Open Studio survey win a $10 gift voucher.

Start the survey

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog

How Media Organizations Achieved Success with Data Integration

Learn how media organizations have achieved success with Data Integration

Read

Definitive Guide to Data Quality

Create systems and workflow to manage clean data ingestion and data transformation.

Download