• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What is the Data Type for GMT Date and Time?

 
Natalie Kopple
Ranch Hand
Posts: 325
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the data type of "GMT Date and Time" Date? or Time? or something else? Thanks.
 
Greg Brannon
Bartender
Posts: 563
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Strictly speaking, there is no Java data type that includes "GMT Date and Time." Java has two classes, Date and Calendar, that can be used to program dates and times. You can find out more about them in the API.

I'm curious where you got the expression "GMT Date and Time" and why it's enclosed in quotes. Is it a phrase you read or heard and just wanted to know more about it?
 
Natalie Kopple
Ranch Hand
Posts: 325
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply. I just want to know more about it and sorry about using quotes.

I have to save the date as well as time (in GMT) as the value of a variable. I would like to know what data type I should give to that variable. Thanks.
 
Greg Brannon
Bartender
Posts: 563
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you look at the Date and Calendar classes? Will they suit your needs?

What will you do with the data and time once you save it? Do you need to perform any calculations with it, e.g. figure out how many hours passed between two of your stored dates? If you simply want to save the date and time, you could do it in a String, "1403 GMT, Wednesday 7 September 2011".

There are many possible answers to your question. Determining the best answer requires more info.
 
Natalie Kopple
Ranch Hand
Posts: 325
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks very much.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15369
40
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Class java.util.Date represents an "absolute" point in time, without timezone information. To store a date and time, you can use a java.util.Date. Where the timezone comes in to play is when you want to display the content of a Date object.

You can use a SimpleDateFormat object to convert a Date to a String for display. You set the timezone on the SimpleDateFormat object to tell it what timezone you want to display:

So, the information about the timezone is not in the Date object itself - it's something that you specify to the SimpleDateFormat object.
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are going to process dates and times a lot, I'd strongly suggest you to check out the JodaTime library. Its documentation is excellent, and the time spent learning its concepts pays back quickly. It provides very good tools to handle dates and times, much better than JDK's Date or Calendar classes in many aspects.
 
Natalie Kopple
Ranch Hand
Posts: 325
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks very much for the detailed explanation. The help I received is great.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic