java - How to convert "MM-dd-yyyy hh:mm" String date format to GMT format? -


my date format "mm-dd-yyyy hh:mm" not current date ,i have send date server before send need change date gmt format when change following code:

private string[] dateconvertor(string datevalue)         {             string date_value[] = null;             string strgmtformat = null;             simpledateformat objformat,objformat1;             calendar objcalendar;             date objdate1,objdate2;             if(!datevalue.equals(""))             {             try             {             //specify format                 objformat1 = new simpledateformat("mm-dd-yyyy,hh:mm");                 objformat1.settimezone(calendar.getinstance().gettimezone());                  objformat = new simpledateformat("mm-dd-yyyy,hh:mm");                 objformat.settimezone(timezone.gettimezone("gmt"));              //convert gmt format             //objformat.settimezone(timezone.getdefault());//);              objdate1=objformat1.parse(datevalue);             //             //objdate2=objformat.parse(datevalue);               //objformat.setcalendar(objcalendar);             strgmtformat = objformat.format(objdate1.gettime());             //strgmtformat = objformat.format(objdate1.gettime());             //strgmtformat=objdate1.tostring();             if(strgmtformat!=null && !strgmtformat.equals(""))              date_value = strgmtformat.split(",");             }             catch (exception e)             {                 e.printstacktrace();                 e.tostring();             }                         {             objformat = null;             objcalendar = null;             }             }             return date_value;          } 

its not change in required format ,i have tried above code first try current timezone , after try change string date timezone after convert gmt. guide me.

thanks in advance.

try below code. first sysout prints date object picks default os timezone i.e. ist in case. second sysout prints date in required format after converting date gmt timezone.

if know timezone of date string set in formatter. assumed need same date format in gmt timezone.

simpledateformat format = new simpledateformat("mm-dd-yyyy,hh:mm");  date date = format.parse("01-23-2012,09:40"); system.out.println(date);  format.settimezone(timezone.gettimezone("gmt")); system.out.println(format.format(date)); 

Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -