Here you can find the source of getUTC(String beforeFormart, String afterFormart, String dateStr)
Parameter | Description |
---|---|
beforeFormart | a parameter |
afterFormart | a parameter |
dateStr | a parameter |
Parameter | Description |
---|---|
ParseException | an exception |
public static String getUTC(String beforeFormart, String afterFormart, String dateStr) throws ParseException
//package com.java2s; //License from project: Open Source License import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; public class Main { public static String getUTC(String beforeFormart, String afterFormart, String dateStr) throws ParseException { SimpleDateFormat be = new SimpleDateFormat(beforeFormart, Locale.US); Date date = be.parse(dateStr); SimpleDateFormat af = new SimpleDateFormat(afterFormart, Locale.US); // af.setTimeZone(TimeZone.getTimeZone("UTC")); String dateUtc = af.format(date); return dateUtc; }//from ww w. j a va2 s.c om public static long parse(String date) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); try { return sdf.parse(date).getTime(); } catch (ParseException e) { e.printStackTrace(); return 0; } } public static long parse(String date, String pattern) { SimpleDateFormat sdft = new SimpleDateFormat(pattern); try { return sdft.parse(date).getTime(); } catch (ParseException e) { e.printStackTrace(); return 0; } } }