How do I display a date with a custom timezone?

后端 未结 4 1207
感动是毒
感动是毒 2021-02-13 08:57

Lets say I have a string that represents a date that looks like this:

\"Wed Jul 08 17:08:48 GMT 2009\"

So I parse that string into a date object like this:

4条回答
  •  逝去的感伤
    2021-02-13 09:43

    Sorry for digging out an old-thread. But I was wondering if there is a java-class that holds all the time-zone-ids as a constant class. So instead of having to hard-code the time-zone-id while setting time-zone like this:

    formatter.setTimeZone(TimeZone.getTimeZone("US/Central"));
    

    we would instead be doing something more standard/uniform:

    formatter.setTimeZone(TimeZone.getTimeZone(SomeConstantClass.US_CENTRAL)); 
    

    where SomeConstantClass.java is a class that holds the constants referring to the different time-zone-ids that are supported by the TimeZone class.

提交回复
热议问题