-1

How Can I convert this java.util.Date format:

2015-01-16 00:00:00.0 

to this java.util.Date format:

2015-01-16 00:00:00 GMT+00:00
Shiroga
  • 145
  • 2
  • 8
  • 20
  • Is it a simple case of output formatting you're considering? (And I guess the change of day from 16 to 01 is accidental) – Luc Jan 14 '15 at 13:01
  • This is the same date! A `Date` object has no notion of a format – fge Jan 14 '15 at 13:03
  • possible duplicate of [How do I convert the date from one format to another date object in another format without using any deprecated classes?](http://stackoverflow.com/questions/12503527/how-do-i-convert-the-date-from-one-format-to-another-date-object-in-another-form) – Jonathan Jan 14 '15 at 13:03

2 Answers2

2

You're going to need to use java.text.SimpleDateFormat.

Something as follows:

final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
System.out.println(sdf.format(new Date()));

would print something like this: 2001-07-04 12:08:56 PDT.

I hope that helps.

Matthew Cachia
  • 4,474
  • 1
  • 13
  • 17
0

Have you tried using the SimpleDateFormat?

http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html

Rekijan Kileren
  • 183
  • 1
  • 3
  • 16