Java UTC Date getUTC(String beforeFormart, String afterFormart, String dateStr)

Here you can find the source of getUTC(String beforeFormart, String afterFormart, String dateStr)

Description

get UTC

License

Open Source License

Parameter

Parameter Description
beforeFormart a parameter
afterFormart a parameter
dateStr a parameter

Exception

Parameter Description
ParseException an exception

Declaration

public static String getUTC(String beforeFormart, String afterFormart, String dateStr) throws ParseException 

Method Source Code


//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;
        }
    }
}

Related

  1. createUtcCalendar()
  2. formatUTC(Date time)
  3. formatUTC(Date time)
  4. getPlatypusConainerClass(Class aLayoutClass)
  5. getUTC()
  6. getUTCCalendar()
  7. getUTCCalendar()
  8. getUTCCalendar(Calendar value)
  9. getUTCCalendarFromDialogString(String dateString)