Java UTC Date getUTCDateFromString(String date)

Here you can find the source of getUTCDateFromString(String date)

Description

get UTC Date From String

License

Open Source License

Declaration

public static Date getUTCDateFromString(String date) throws ParseException, Exception 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;

public class Main {
    public static Date getUTCDateFromString(String date) throws ParseException, Exception {
        DateFormat df = new SimpleDateFormat("yyyyMMddHHmmss", Locale.ENGLISH);
        Date result = df.parse(date);
        return getUTCDate(result.getTime());
    }/*w w  w.j  av  a 2 s  .co m*/

    public static Date getUTCDate(Long milliseconds) {
        //Date converted to UTC
        if (milliseconds == null)
            return null;

        TimeZone currentTimezone = TimeZone.getDefault();
        Date currentDateUTC = new Date(milliseconds - currentTimezone.getRawOffset());

        return currentDateUTC;
    }
}

Related

  1. getUTCCalendar()
  2. getUTCCalendar(Calendar value)
  3. getUTCCalendarFromDialogString(String dateString)
  4. getUTCDate()
  5. getUtcDate(String date, String pattern)
  6. getUtcDateString()
  7. getUtcDateStringFromTimestamp(Date timeStamp)
  8. GetUTCdatetimeAsString()
  9. GetUtcNow()