programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Jeanne Boyarsky
• Ron McLeod
• Paul Clapham
• Liutauras Vilda
Sheriffs:
• paul wheaton
• Rob Spoor
• Devaka Cooray
Saloon Keepers:
• Stephan van Hulst
• Tim Holloway
• Carey Brown
• Frits Walraven
• Tim Moores
Bartenders:
• Mikalai Zaikin

# Time Calculation according to the TimeZone

Ranch Hand
Posts: 5575
• Number of slices to send:
Optional 'thank-you' note:
Hi,
i have to calculate time according to the TimeZone. the thing is i am getting hour in not a railway time(example railway time means 1pm=13 hr,3pm=15,2AM=2 only ).. or else
---------------------------------------------
how can i know whether it is AM or PM
-----------------------------------------------

Sheriff
Posts: 9708
43
• Number of slices to send:
Optional 'thank-you' note:
Hi!

If you want, you can get time in 24hr format by calling cal.get(Calendar.HOUR_OF_DAY)...as far as AM or PM is concerned...you can use cal.get(Calendar.AM_PM), it will return 0 if the time is AM and 1 if it is PM

Greenhorn
Posts: 5
• Number of slices to send:
Optional 'thank-you' note:

Originally posted by seetharaman venkatasamy:
Hi,
i have to calculate time according to the TimeZone. the thing is i am getting hour in not a railway time(example railway time means 1pm=13 hr,3pm=15,2AM=2 only ).. or else
---------------------------------------------
how can i know whether it is AM or PM
-----------------------------------------------

int i= cale.get(Calendar.AM_PM);
if it returns 0 means AM
if it returns 1 means PM

Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
• Number of slices to send:
Optional 'thank-you' note:
Thanks somuch Ankit Garg and Sanjeeva

Sheriff
Posts: 22791
131
• Number of slices to send:
Optional 'thank-you' note:

Originally posted by sanjeeva vem:

int i= cale.get(Calendar.AM_PM);
if it returns 0 means AM
if it returns 1 means PM

Actually it returns Calendar.AM and Calendar.PM. Those happen to be 0 and 1 respectively, but you should really compare them against these constants. Just like you need to compare weekdays against Calendar.SUNDAY until Calendar.SATURDAY, and months against Calendar.JANUARY until Calendar.DECEMBER. The latter is especially important because months are 0-based - month 1 is not January but February.

Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
• Number of slices to send:
Optional 'thank-you' note:
Thanks Rob prime

 Destroy anything that stands in your way. Except this tiny ad: a bit of art, as a gift, the permaculture playing cards https://gardener-gift.com