The Artima Developer Community
Sponsored Link

Java Answers Forum
String to UTC Time

2 replies on 1 page. Most recent reply: Jul 2, 2004 12:28 AM by Mike Nikles

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Mike Nikles

Posts: 2
Nickname: mikenikles
Registered: Jul, 2004

String to UTC Time Posted: Jul 1, 2004 2:10 AM
Reply to this message Reply
Advertisement
Hello<br><br>

Ok I've a problem by parsing a String to a date..
<br><br>
I want to parse a String (20040328.0100) to a date.
The format is like ddMMyyyy.HHmm.
<br><br>
The result is "Sun Mar 28 03:00:00 CEST 2004" but should
be a timestamp in UTC with 01 as hour, not 03.
<br><br>
I hope someone can help me with this problem!
<br><br>
Here my code:
<br><br>
<pre>
private void testUtcTime()
{

String lDateAsStr = "28032004.0100";

// define the format of the date
SimpleDateFormat lSDF = new SimpleDateFormat ("ddMMyyyy.HHmm");

// set timezone to use in interpreting the date
TimeZone lTimeZoneUTC = TimeZone.getTimeZone ("UTC");
GregorianCalendar lCalendar = new GregorianCalendar(lTimeZoneUTC);
lSDF.setCalendar(lCalendar);

//System.out.println("calendar: " + utc.toString());

try
{
// set timestamp
Date lDate = lSDF.parse(lDateAsStr);
lCalendar.setTime(lDate);

// calendar is now ready with both timezone and timestamp
Date lDate2 = lCalendar.getTime();
System.out.println(lDate2.toString());
}
catch (ParseException e)
{
System.out.println("bad date: " + e.toString());
}
}
</pre>


Harry Paek

Posts: 3
Nickname: harrypaek
Registered: Jul, 2004

Re: String to UTC Time Posted: Jul 1, 2004 6:09 PM
Reply to this message Reply
Hi!

You can get by this before Display
ie. Set the display formatter


// Set formatter What you want
SimpleDateFormat dSDF = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US);
// Set Display Time Zone
dSDF.setTimeZone(lTimeZoneUTC);
// Display It!!!
System.out.println(dSDF.format(lDate2));


Good Luck!
Bye.

Mike Nikles

Posts: 2
Nickname: mikenikles
Registered: Jul, 2004

Re: String to UTC Time Posted: Jul 2, 2004 12:28 AM
Reply to this message Reply
Hey!

Thanks a lot, it works fine!

Flat View: This topic has 2 replies on 1 page
Topic: Table still does not get updated--- fixed. But got another problem? Previous Topic   Next Topic Topic: Table still does not get updated

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use