hello i have a date and time string in 24 hour format but i want it in 12 hour how i can do this my string is
String date_st="12 Nov, 2014 23:13"
i am doing this
SimpleDateFormat dateformat = new SimpleDateFormat("dd' 'MMM,' 'yyyy HH:mm aa");
but its not converting according to my need it shows 23:13 PM
i want to show in following format
String con_date= "12 Nov, 2014 11:13 PM"
how i can do this?
You need two formats: one to parse, and one to format. You need to parse from
StringtoDatewith oneDateFormat, then format thatDateinto aStringwith the other format.Currently, your single
SimpleDateFormatis half way between - you've gotHHwhich is 24-hour, but you've also gotaawhich is for am/pm. You wantHHwithout theaafor input, andhhwith theaafor output. (It's almost never appropriate to have bothHHandaa.)Note that I'm setting the locale to US so it can always parse "Nov", and the time zone to UTC so you don't need to worry about certain times being skipped or ambiguous.