SHARE
TWEET

Untitled

a guest Feb 19th, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. String date = "9/13/2012";
  2. String time = "5:48pm";
  3.    
  4. SimpleDateFormat inputFormat = new SimpleDateFormat("MM/dd/yyyy h:mma", Locale.US);
  5. inputFormat.setTimeZone(TimeZone.getTimeZone("Etc/UTC");
  6. Date date = inputFormat.parse(date + " " + time);
  7.  
  8. // Or whatever format you want...
  9. SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.US);
  10. outputFormat.setTimeZone(targetTimeZone);
  11. String outputText = outputFormat.format(date);
  12.    
  13. String date = "9/13/2012";
  14.     String time = "5:48pm";
  15.  
  16.     String[] dateParts = date.split("/");
  17.     Integer month = Integer.parseInt(dateParts[0]);
  18.     Integer day = Integer.parseInt(dateParts[1]);
  19.     Integer year = Integer.parseInt(dateParts[2]);
  20.  
  21.     String[] timeParts = time.split(":");
  22.     Integer hour = Integer.parseInt(timeParts[0]);
  23.     Integer minutes = Integer.parseInt(timeParts[1].substring(0,timeParts[1].lastIndexOf("p")));
  24.  
  25.     DateTime dateTime = new DateTime(year, month, day, hour, minutes, DateTimeZone.forID("Etc/GMT"));
  26.     dateTime.withZone(DateTimeZone.forID("Etc/GMT+8"));
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top