0

I tried below to get GMT Time

SimpleDateFormat f = new SimpleDateFormat("ddmmyyyyHHmmss");
f.setTimeZone(TimeZone.getTimeZone("GMT"));
Date date = f.parse("13072016132825");
System.out.println("GMT Time"+f.format(date.getTime()));
Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331
User30892
  • 9
  • 1
  • 3
    You need capital MM for months, not mm. – Dawood ibn Kareem Jul 26 '16 at 07:12
  • @ David I tried with capital MM Still I am getting same string in input. – User30892 Jul 26 '16 at 07:20
  • Sure. But you haven't actually said what your problem is, or asked a question. That's why I didn't provide an answer (and it baffles me that two people provided answers without knowing what the question is). So, what's actually going wrong for you? How can I help? – Dawood ibn Kareem Jul 26 '16 at 07:22
  • I have string which contains EST datetime and I wants to convert it to GMT datetime. – User30892 Jul 26 '16 at 07:25
  • Yes, and what is going wrong for you, when you try the code above? – Dawood ibn Kareem Jul 26 '16 at 07:26
  • Probably, you need to set the time zone to EST, then call `f.parse`. After that, set the time zone to GMT and call `f.format`. As it is, you're doing your `parse` step with a `SimpleDateFormat` whose time zone is GMT. – Dawood ibn Kareem Jul 26 '16 at 07:27
  • @BasilBourque this is almost certainly NOT a duplicate of that other question. – Dawood ibn Kareem Jul 26 '16 at 07:29
  • @DavidWallace The problem and the solution is the same, using `mm` versus `MM` in the formatting pattern. And many many others as well. Do you suggest Stack Overflow have a Question for every possible permutation of parsing pattern all sharing the same `MM` problem? – Basil Bourque Jul 26 '16 at 07:32
  • @BasilBourque the OP hasn't even clarified what the problem is yet; although they've said quite clearly it's not the `mm` vs `MM` thing. So NOT a duplicate. I suspect it's the fact that they're doing the `parse` with the wrong timezone, but I don't know. – Dawood ibn Kareem Jul 26 '16 at 07:34
  • When the author edits their Question to first eliminate the obvious syntax problem, and secondly clarify the underlying nature of the unspecified problem, we can reopen the Question. But it seems silly to entertain a Question asking about code that can't possibly be working. – Basil Bourque Jul 26 '16 at 07:38
  • Fair enough, although "unclear what you're asking" would have been a better close reason than "duplicate of ..." when it's clearly not a duplicate. – Dawood ibn Kareem Jul 26 '16 at 07:40
  • Thanks @david now I got it. – User30892 Jul 26 '16 at 07:44

0 Answers0