Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  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"));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement