[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 591
  • Last Modified:

Time and date format

How do I get the Date and Timstamp in   "yyyy:MM:dd:HH:mm:ss"

and reference to GMT ( GMT time)

0
TLTEO
Asked:
TLTEO
  • 3
  • 3
  • 2
1 Solution
 
objectsCommented:
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
 
amareldoCommented:
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
 
objectsCommented:
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
TLTEOAuthor Commented:
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
 
objectsCommented:
You need to parse them (using SimpleDateFormat) to get Date objects and then compare those using Date methods provided.
0
 
amareldoCommented:
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
 
TLTEOAuthor Commented:
ok  great got it tks
0
 
amareldoCommented:
objects,

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

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 3
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now