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?
Always learning Java, currently using Eclipse on Fedora.
Linux user#: 501795
Joined: May 06, 2003
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.
Joined: Oct 24, 2010
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.
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.
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.
Joined: May 06, 2003
Thanks very much for the detailed explanation. The help I received is great.
subject: What is the Data Type for GMT Date and Time?