简体   繁体   中英

how to convert yyyy-mm-ddThh:mm:ss+05:30 to hh:mm:ss AM/PM in android

I am receiving date and time format as mentioned below

2016-04-13T00:12:33+05:30

i need to convert above format to HH:MM:SS AM/PM

can any one guide me,your response will be appreciated......

SimpleDateFormat formatter = new SimpleDateFormat("hh:mm:ss a");
Log.i("date ====== " + formatter.format("2016-04-13T00:12:33+05:30"));

Android has the DateFormat class for parsing and reformatting dates as Strings, but JodaTime is much better. JodaTime is small and can handle what you're looking for in just a couple lines of code.

You need first String to Date using Simple forma tor

Then date need to change to formatResult fro expected result

 SimpleDateFormat format = new SimpleDateFormat("dd-M-yyyy hh:mm:ss", Locale.ENGLISH);

  SimpleDateFormat formatResult  = new SimpleDateFormat("hh:mm aa");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM