I am getting date value from database like \"2013-02-27 06:06:30\" using StringTokenizer I will get time separately like below
String startTime = \"2013-02
I recommend using a DateFormat, like SimpleDateFormat
try {
String timeLong = "2013-02-27 06:06:30";
String timeShort = "16:06 AM";
SimpleDateFormat formatLong = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US);
SimpleDateFormat formatShort = new SimpleDateFormat("hh:mm aa", Locale.US);
Log.v("out", formatShort.format(formatLong.parse(timeLong)));
Log.v("out", formatShort.format(formatShort.parse(timeShort)));
} catch (ParseException e) {
e.printStackTrace();
}
I am tired today and I feel like I am missing something in this code so I might amend it later, but it does work and it doesn't (directly) call the deprecated Date class.