I have a string of date which is in the format of hh:mm. I want to convert it into yyyy-MM-dd HH:mm:ss this format and convert it into UTC time zone and save it into database.
I tried this:
private void returnPickupTimeUTC(){
String pickupTime = "04:05 pm";
Date pickDate = null;
SimpleDateFormat sdf = new SimpleDateFormat("hh:mm a",Locale.US);
try{
pickDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(pickupTime);
} catch (ParseException ex){
}
Calendar calendar = Calendar.getInstance();
calendar.setTime(pickDate);
Date time = calendar.getTime();
SimpleDateFormat outputFmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss",Locale.US);
outputFmt.setTimeZone(TimeZone.getTimeZone("UTC"));
pickupTimeStr =outputFmt.format(time);
System.out.println(outputFmt.format(time));
}