java - Parsing date to remove timezone -
i use following simpledateformat parse string,
simpledateformat ft= new simpledateformat("eee mmm dd hh:mm:ss yyyy"); string notimezone = ft.format(startdatetime); date date = ft.parse(notimezone);
startdatetime date object value in format "thu mar 06 12:27:55 ist 2014".
in notimezone variable get, thu mar 06 12:27:55 2014
i expecting output in variable date as, thu mar 06 12:27:55 2014
but getting same , thu mar 06 12:27:55 ist 2014.
how remove time zone date object.
please help.
java.util.date does
not have timezone
. not aware of timezone
.
when print, java picks default time zone.
conceptually, cannot have date time without timezone. date time has in 1 , 1 zone. may convert other zones, can never without zone.
if business use case requires awareness of time zone, prefer use calendar
class, or joda time
. avoid playing date class. if business use cases not require time zone awareness, go ahead date. assume date instances in default time zone.
best thing use calendar
(or joda time
). calendar
bit unintuitive able job done. not without reason date class deprecated.
initialize calendar
timezone
(check out available constructors). use dateformat
convert , show in ui
in whatever time zone wish to. posted code in previous question. might you. stuck in similar problem. have dates in db in 1 time zone. display them in time zone on ui, need convert datetime zone.
Comments
Post a Comment