java - Not able to properly display time in AM, PM format in Android -


i have achieved time formate using am-pm below code

date date = new simpledateformat("h:m").parse((mhour+":"+mminute)); string newstring = new simpledateformat("hh:mm a").format(date); system.out.println("time - "+newstring); 

but in above code there 1 problem

if set time 12:00 am in timepickerdialog display 12:00 am if change time in timepickerdialog 12:00 pm still display 12:00 am

it's because h 12 hour time format. , timepickerdialog sending 24 hour format.

use,

date date = new simpledateformat("h:m").parse((mhour+":"+mminute)); // upper h here. 

edit:

simpledateformat java doc, check out date , time patterns section.


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -