Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > UTC time in millisecond

Reply
Thread Tools

UTC time in millisecond

 
 
palmis
Guest
Posts: n/a
 
      01-10-2006
Hi,
How can I get UTC time in millisecond?
I have used System.currentTimeMillis() but it isn't correct!
Can you help me?
thanks
Palmis.

 
Reply With Quote
 
 
 
 
Nigel Wade
Guest
Posts: n/a
 
      01-10-2006
palmis wrote:

> Hi,
> How can I get UTC time in millisecond?
> I have used System.currentTimeMillis() but it isn't correct!
> Can you help me?
> thanks
> Palmis.


In what way is it not correct?

Don't forget that your OS is very unlikely to be able to provide time to
millisecond accuracy. Common OS clock accuracy is of the order of 50-100ms.

Some OS provide very accurate timing, but not those typically available on the
desktop or server. It's normally the preserve of RTOS, where timing is
critical.

--
Nigel Wade, System Administrator, Space Plasma Physics Group,
University of Leicester, Leicester, LE1 7RH, UK
E-mail : http://www.velocityreviews.com/forums/(E-Mail Removed)
Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555
 
Reply With Quote
 
 
 
 
Steve Horsley
Guest
Posts: n/a
 
      01-10-2006
palmis wrote:
> Hi,
> How can I get UTC time in millisecond?
> I have used System.currentTimeMillis() but it isn't correct!
> Can you help me?
> thanks
> Palmis.
>


If system.currentTimeMillis() is returning the wrong time then
there is probably something wrong with your operating system
installation.

Is it wrong by just a few hours? The difference between local and
UTC time? I have seen this on some Windows installations. You may
be able to fix it with some time settings in the Windows Control
Panel.

Steve
 
Reply With Quote
 
S.B
Guest
Posts: n/a
 
      01-10-2006

"palmis" <(E-Mail Removed)> a écrit dans le message de news:
(E-Mail Removed). com...
> Hi,
> How can I get UTC time in millisecond?
> I have used System.currentTimeMillis() but it isn't correct!
> Can you help me?
> thanks
> Palmis.
>


if your time zone is different from "GMT+0", the value returned by
System.currentTimeMillis() is not an UTC time, it is a local time. To
obtain the UTC time you must convert the time returned by
currentTimeMillis()
like in the code below :

long lCurrentTime;
GregorianCalendar lGmtCalendar;
long lUTCtime;

lGmtCalendar = new GregorianCalendar(new SimpleTimeZone(0,"GMT+0"));

gmtCalendar.setTimeInMillis(System.currentTimeMill is());

lUTCtime = lGmtCalendar.getTimeInMillis();





 
Reply With Quote
 
palmis
Guest
Posts: n/a
 
      01-10-2006
Excuse me,
I don't know very well differences between utc time and system time.
Can you explain me, please?
Thanks.
Palmis

 
Reply With Quote
 
Thomas Weidenfeller
Guest
Posts: n/a
 
      01-10-2006
S.B wrote:
> if your time zone is different from "GMT+0", the value returned by
> System.currentTimeMillis() is not an UTC time, it is a local time.


That statement is plain and simply wrong. Unless you misconfigured your
system clock.

/Thomas


--
The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/...g/java/gui/faq
http://www.uni-giessen.de/faq/archiv....java.gui.faq/
 
Reply With Quote
 
palmis
Guest
Posts: n/a
 
      01-10-2006
So what is the better solution?

 
Reply With Quote
 
zero
Guest
Posts: n/a
 
      01-10-2006
Thomas Weidenfeller <(E-Mail Removed)> wrote in news:dq0lgs$oq5$1
@news.al.sw.ericsson.se:

> S.B wrote:
>> if your time zone is different from "GMT+0", the value returned by
>> System.currentTimeMillis() is not an UTC time, it is a local time.

>
> That statement is plain and simply wrong. Unless you misconfigured your
> system clock.
>
> /Thomas
>
>


not exactly misconfigure, it's just a choice you make on setup.

--
Beware the False Authority Syndrome
 
Reply With Quote
 
zero
Guest
Posts: n/a
 
      01-10-2006
"palmis" <(E-Mail Removed)> wrote in
news:(E-Mail Removed) ups.com:

> Excuse me,
> I don't know very well differences between utc time and system time.
> Can you explain me, please?
> Thanks.
> Palmis
>


UTC is (more or less) the same as GMT, meaning it is the time at the
Greenwich Meridian, which is in England. If you're for example in
Europe, your local time will be 1-2 hours (depending on summer or winter
time) different from UTC.

Your system time is just the time to which your computer's hardware clock
is set. This could be anything, it could even me completely wrong.
Usually however, it is set to either your local time, or UTC.

Normally, the operating system compensates the hardware clock setting, so
that it (the OS) always shows your local time.

System.currentTimeMillis() is indeed what you need. It may help if you
explain why you think it is wrong, and what you need it for.

--
Beware the False Authority Syndrome
 
Reply With Quote
 
Roman Gusev
Guest
Posts: n/a
 
      01-10-2006
palmis wrote:
> So what is the better solution?


I use the following code:
Calendar cal = Calendar.getInstance();
cal.add(
Calendar.MILLISECOND,
-cal.get(Calendar.DST_OFFSET) -
cal.get(Calendar.ZONE_OFFSET));
long lUTCtime = cal.getTime();
It takes into account summer/winter time transition.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
logging time format millisecond precision Alex van der Spek Python 0 07-19-2012 08:06 PM
How to store as absolute an org.jfree.data.time.Millisecond etantonio Java 1 03-16-2009 02:07 PM
convert time string in UTC to time in local time davelist@mac.com Python 1 03-11-2007 12:57 AM
Covert UTC String to UTC Datetime =?Utf-8?B?aGVuaw==?= ASP .Net 3 05-07-2006 06:25 PM
Millisecond in time. Warren Ruby 11 07-02-2003 09:50 AM



Advertisments