android - get am/pm in gmt timezone -


i trying am/pm in gmt timezone code crashing error. how can change existing/default timezone pick timepicker in gmt am/pm ?

code:

 string selectedhour="15";         string selectedminute="32";         string am_pm="pm";         simpledateformat sdf = new simpledateformat("hh:mm a", locale.us);         date testdate = null;         try {             testdate = sdf.parse(selectedhour+" "+selectedminute+" "+am_pm);         }catch(exception ex){             ex.printstacktrace();         }         simpledateformat formatter = new simpledateformat("a");         formatter.settimezone(timezone.gettimezone("gmt"));         string newformat = formatter.format(testdate);         system.out.println(".....date..." + newformat); 

error:

system.err: java.text.parseexception: unparseable date: "15 32 pm" (at offset 2)   system.err:     @ java.text.dateformat.parse(dateformat.java:579) 

your code should parse date

testdate = sdf.parse(selectedhour+":"+selectedminute+" "+am_pm); 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -