• Post Reply Bookmark Topic Watch Topic
  • New Topic

Time Calculation according to the TimeZone  RSS feed

 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
-----------------------------------------------




please anyone help me
 
Ankit Garg
Sheriff
Posts: 9610
37
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
sanjeeva vem
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
-----------------------------------------------




please anyone help me



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
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks somuch Ankit Garg and Sanjeeva
 
Rob Spoor
Sheriff
Posts: 21133
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rob prime
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!