Solved

Time and date format

Posted on 2001-09-02
8
581 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
  • 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
 

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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
factorial example challenge 10 62
noX challenge 17 76
What is the latest versions eclipse neon 2 122
bitbucket vs gitbucket 3 32
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

760 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now