wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes What is the Data Type for GMT Date and Time? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "What is the Data Type for GMT Date and Time?" Watch "What is the Data Type for GMT Date and Time?" New topic
Author

What is the Data Type for GMT Date and Time?

Natalie Kopple
Ranch Hand

Joined: May 06, 2003
Posts: 325
Is the data type of "GMT Date and Time" Date? or Time? or something else? Thanks.
Greg Brannon
Bartender

Joined: Oct 24, 2010
Posts: 561
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
Natalie Kopple
Ranch Hand

Joined: May 06, 2003
Posts: 325
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

Joined: Oct 24, 2010
Posts: 561
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

Joined: May 06, 2003
Posts: 325
Thanks very much.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14278
    
  21

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.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3610
    
  60

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

Joined: May 06, 2003
Posts: 325
Thanks very much for the detailed explanation. The help I received is great.
 
 
subject: What is the Data Type for GMT Date and Time?