-2

If I have a date supplied to a system written in Java, is there any way of telling if it is GMT or BST?

Mr Morgan
  • 2,215
  • 15
  • 48
  • 78
  • How might it be done? – Mr Morgan Jul 11 '13 at 11:18
  • 2
    Depends on if you're using a `Date`, a `Calendar` or something else. What are you using? – Shark Jul 11 '13 at 11:19
  • The date is simply received in format YYYY-MM-DD HH:MM:SS as a string. – Mr Morgan Jul 11 '13 at 11:19
  • 5
    Then no. There's no information about time zone in that string. – jpw Jul 11 '13 at 11:20
  • As a string? In that case, no, you cannot find out what it is as it carries no meta-data. How about extending it to include a timezone 3 letter stamp? – Shark Jul 11 '13 at 11:20
  • oh my. a string. so much data. – jdero Jul 11 '13 at 11:24
  • "The date is simply received in format YYYY-MM-DD HH:MM:SS as a string" - what does this have to do with Java then? In the string there is no information about timezone, so it doesn't matter where this string goes to - the information isn't going to suddenly appear out of nowhere. – mvmn Jul 11 '13 at 11:34

1 Answers1

0

For formatting, you should really use a DateFormat implementation (e.g. SimpleDateFormat). That will let you specify the time zone (and output format).

Ultimately, you need to post code so we know what a "date supplied to a system" looks like.

It can always be identified. (EDIT: Unless you just got a string, like you did.)

There's something like this if you're interested in a TimeZone class.

Use those proper DateFormat Java Docs. Answer your own questions, then ask the ones you can't answer. That's what SO is for.

The Date class is timezone dependent.

One google search prevents a duplicate like this.

jdero
  • 1,797
  • 3
  • 21
  • 36
  • 1
    Or [this answer](http://stackoverflow.com/questions/1516213/java-util-date-is-using-timezone) – Shark Jul 11 '13 at 11:21
  • The answer that tried to be useful on a useless question... – jdero Jul 11 '13 at 11:25
  • This one or the one I posted? :) – Shark Jul 11 '13 at 11:26
  • I just meant my 4:30am internet scavenging... You're good :P – jdero Jul 11 '13 at 11:27
  • 1
    It's a valid answer and deserves at least an upvote ;) For a complete answer, references to `TimeZone` and `Calendar` could be added, along with a `SimpleDateFormat` example. If you're bored, expand on it ;) Maybe [this](http://stackoverflow.com/questions/11309264/java-calendar-timezone-issue) ? – Shark Jul 11 '13 at 11:29