How do I display a date with a custom timezone?

后端 未结 4 1300
闹比i
闹比i 2021-02-13 09:28

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:49

    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.

提交回复
热议问题