Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
alevy
Specialist
Specialist

[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.
Labels (2)
1 Solution

Accepted Solutions
_AnonymousUser
Specialist III
Specialist III

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

View solution in original post

7 Replies
janhess
Creator II
Creator II

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.
alevy
Specialist
Specialist
Author

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.
janhess
Creator II
Creator II

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.
alevy
Specialist
Specialist
Author

Surely there's a way to do it with Java?
alevy
Specialist
Specialist
Author

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.
_AnonymousUser
Specialist III
Specialist III

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

Which was added in v6.0.1.