String to Date Parsing Java -


i trying parse utc timezone in date, first formatting simpledateformat , passing "utc" in formatter timezone. problem when trying parse string date, again change time without utc format.

private date getdateutc_converter(date datestring) {          simpledateformat formatter = new simpledateformat("eee mmm dd hh:mm:ss z yyyy");         formatter.settimezone(timezone.gettimezone("utc"));          // datestring = mon feb 01 13:00:00 gmt+04:00 2016         date value = null;          try {//  mon feb 01 13:00:00 gmt+04:00 2016         // after utc  mon feb 01 09:00:00 +0000 2016             string abc = formatter.format(datestring);             value = formatter.parse(abc);        // after getting   mon feb 01 13:00:00 gmt+04:00 2016 here.          } catch (parseexception e) {             e.printstacktrace();         }          return value;         } 

don't format input string. parse straight away.

private date getdateutc_converter(string datestring) {      simpledateformat parser = new simpledateformat("eee mmm dd hh:mm:ss z yyyy");     parser.settimezone(timezone.gettimezone("utc"));     try {         // suppose datestring = "mon feb 01 13:00:00 gmt+04:00 2016"         // returns "mon feb 01 09:00:00 +0000 2016"         return parser.parse(datestring);     } catch (parseexception e) {         e.printstacktrace();     }     return null; } 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -