1

Can someone show me a piece of java code that parses this date:

2009-08-05

INTO THIS GMT DATE:

2009/217:00:00

====

what i have so far is:

       java.text.SimpleDateFormat format = new SimpleDateFormat("yyyy-mm-dd");

       java.util.Calendar cal = Calendar.getInstance(new SimpleTimeZone(0, "GMT"));
       format.setCalendar(cal);
       java.util.Date date = format.parse(sdate);

but its not working

Erick Robertson
  • 32,125
  • 13
  • 69
  • 98
Afamee
  • 5,160
  • 9
  • 38
  • 43

3 Answers3

8

Here is the format you're looking for:

Date date = new SimpleDateFormat("yyyy-MM-dd").parse("2009-08-05");
String parsedDate = new SimpleDateFormat("yyyy/D:HH:mm").format(date);
Quinn Taylor
  • 44,553
  • 16
  • 113
  • 131
Tommy
  • 4,011
  • 9
  • 37
  • 59
2
format.setTimeZone(TimeZone.getTimeZone("GMT"));

That's how to set it to GMT at least. Not sure where you are getting 2009/217 from 2009-08-05

Gandalf
  • 9,648
  • 8
  • 53
  • 88
0
SimpleDateFormat dateFormatGmt = new SimpleDateFormat("dd:MM:yyyy HH:mm:ss");
    dateFormatGmt.setTimeZone(TimeZone.getTimeZone("GMT"));
    System.out.println(dateFormatGmt.format(new Date())+"");

This will convert your local time to GMT.

nithinreddy
  • 6,167
  • 4
  • 38
  • 44