Results 1 to 11 of 11
- 04-20-2011, 04:39 PM #1
Member
- Join Date
- Dec 2009
- Posts
- 36
- Rep Power
- 0
Still need some help.. Getting current time somewhere
Hi guys, i'm trying to get the current time at the PDT
i tried the following:
But it doesn't work, i also tried removing the Locale.US, but still the same..Java Code:Calendar c = Calendar.getInstance(TimeZone.getTimeZone("PDT"), Locale.US); c.getDate().toString();
the output is the same time as i have.. but it should at this time be like 9AM, while it gives me 6PM (my time)
thanks in advance!
- 04-20-2011, 08:42 PM #2
Member
- Join Date
- Dec 2009
- Posts
- 36
- Rep Power
- 0
anyone can help me?
- 04-20-2011, 08:46 PM #3
Senior Member
- Join Date
- Jan 2011
- Location
- Rizal Province, Philippiines
- Posts
- 167
- Rep Power
- 0
Im not sure but you can try this:
IF THE ABOVE DOESN'T HELP, I THINK IT HAS SOMETHING TO DO WITH YOU COMPUTER CLOCK SETTING, SET IT TO LOCALE USJava Code:Calendar now = Calendar.getInstance(); String hourFormat, minuteFormat, secondsFormat; int hour = now.get(Calendar.HOUR), minute = now.get(Calendar.MINUTE), seconds = now.get(Calendar.SECOND), currentYear = Integer.parseInt(yearInteger.format(now.getTime())), currentMonth = Integer.parseInt(monthInteger.format(now.getTime())), timeField.setText(" " + hourFormat + ":" + minuteFormat + ":" + secondsFormat);
- 04-20-2011, 08:50 PM #4
Member
- Join Date
- Dec 2009
- Posts
- 36
- Rep Power
- 0
- 04-21-2011, 03:06 AM #5
You've missed that Date doesn't have a TimeZone -- it represents an instant in time. Date's toString() does however use the default TimeZone to format its output, as you have already observed. Nothing you can do will change that.
Use SimpleDateFormat#setTimeZone(...) and format(...)
db
- 04-21-2011, 12:48 PM #6
Member
- Join Date
- Dec 2009
- Posts
- 36
- Rep Power
- 0
Yep, indeed it works
Thanks!
- 04-21-2011, 12:58 PM #7
jojo.
May i know which OS you have been using so far?
Why i am asking is this , i too have been suffering the same issue in my Windows 7.Mak
(Living @ Virtual World)
- 04-21-2011, 12:59 PM #8
Member
- Join Date
- Dec 2009
- Posts
- 36
- Rep Power
- 0
currently XP, but it works you jsut need to do it like this: (for my example)
DateFormat PDTFormat = new SimpleDateFormat("HH:mm:ss");
PDTFormat.setTimeZone(TimeZone.getTimeZone("Americ a/Los_Angeles"));
System.out.println("time "+PDTFormat.format(c));
- 04-21-2011, 01:28 PM #9
jojo Thanks a lot. With the help of code u have sent, I fixed my problem Thanks a lot..
Mak
(Living @ Virtual World)
- 04-21-2011, 01:30 PM #10
Member
- Join Date
- Dec 2009
- Posts
- 36
- Rep Power
- 0
np; glad it worked! ;)
- 04-21-2011, 01:47 PM #11
Similar Threads
-
JAVA Programmers Wanted - Full-Time and Part-Time Positions open
By javatrek2020 in forum Jobs OfferedReplies: 3Last Post: 08-23-2011, 12:46 PM -
need help with getting current time in Millis
By Clerek in forum New To JavaReplies: 11Last Post: 01-26-2011, 05:50 AM -
Code for - On click of button current date & time should be assignesd to label.
By amartya51 in forum Suggestions & FeedbackReplies: 1Last Post: 08-16-2010, 10:49 AM -
Current Time in millisecs
By jitman in forum New To JavaReplies: 1Last Post: 03-11-2010, 05:16 PM -
how to get the current date and time
By valery in forum New To JavaReplies: 1Last Post: 08-03-2007, 06:05 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks