Solved

Time and date format

Posted on 2001-09-02
8
586 Views
Last Modified: 2012-05-04
How do I get the Date and Timstamp in   "yyyy:MM:dd:HH:mm:ss"

and reference to GMT ( GMT time)

0
Comment
Question by:TLTEO
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 92

Expert Comment

by:objects
ID: 6449661
Use SimpleDateFormat to format your date object:

TiomeZone tz = TimeZone.getTimeZone("GMT");
SimpleDateFormat fmt = new SimpleDataFormat("yyyy:MM:dd:HH:mm:ss");
fmt.setTimeZone(tz);
System.out.println(fmt.format(date));
0
 
LVL 1

Expert Comment

by:amareldo
ID: 6449676
Hi,

If you want the reference to GMT at your date you should change the code from 'objects' this way:

TimeZone tz = TimeZone.getTimeZone("here put your time zone");
SimpleDateFormat fmt = new SimpleDataFormat("yyyy:MM:dd:HH:mm:ss zzzz"); // <-- 'zzzz' this will put the GMT reference
fmt.setTimeZone(tz);
System.out.println(fmt.format(new Date(System.currentTimeMillis()));

That will show you the date and the GMT reference.

Amareldo.
0
 
LVL 92

Expert Comment

by:objects
ID: 6449689
All adding zzzz will do as display the time zone details which I don't think is what TLTEO wants. (I think) they want to display the time in GMT.
0
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 

Author Comment

by:TLTEO
ID: 6449842
How do i compare

2001:09:03:06:17:05 agt  2001:09:03:07:17:05

to show that the latter is after the former ?

0
 
LVL 92

Accepted Solution

by:
objects earned 20 total points
ID: 6449850
You need to parse them (using SimpleDateFormat) to get Date objects and then compare those using Date methods provided.
0
 
LVL 1

Expert Comment

by:amareldo
ID: 6449874
Well....

1. I think that when TLTEO ask to show "reference to GMT"
It's mean that you want to show what is your current place according to GMT and not printing the GMT time...

2. To compare 2 dates the best thing to do will be to geet their 'long' value. (you can do it be: date.getTime() )
When you have your long value it's very easy to check the bigest with simple IF.

(The option of parsing is not as easy as that...)

Amarldo.
0
 

Author Comment

by:TLTEO
ID: 6449881
ok  great got it tks
0
 
LVL 1

Expert Comment

by:amareldo
ID: 6449906
objects,

I love your country. It's the most amazing place on earth!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to get all the API from website? 11 129
running on tomcat not jboss eap 7.0 3 33
jsp error 6 47
Github api to fetch the number of collaborators in a git repo 1 31
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question