Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static Date convertStringToDate(String dateFormat, String dateInString) throws ParseException {
- Calendar cal = Calendar.getInstance();
- SimpleDateFormat formatter = new SimpleDateFormat(dateFormat);
- try {
- formatter.setTimeZone(TimeZone.getTimeZone("UTC"));
- cal.setTime(formatter.parse(dateInString));
- } catch (Exception e) {
- formatter = new SimpleDateFormat(dateFormatDefault);
- formatter.setTimeZone(TimeZone.getTimeZone("UTC"));
- cal.setTime(formatter.parse(dateInString));
- }
- return cal.getTime();
- }
- //cara penggunaan
- Date createdAt = convertStringToDate("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", "2019-11-16T06:02:46");
- Long timestamp = createdAt.getTime();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement