Java Date Now getCurrentUtcDate()

Here you can find the source of getCurrentUtcDate()

Description

get Current Utc Date

License

Open Source License

Declaration

public static Date getCurrentUtcDate() 

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.TimeZone;

public class Main {
    static final String DATEFORMAT = "yyyy-MM-dd HH:mm:ss";
    static final String UTC_TIMEZONE_CODE = "UTC";

    public static Date getCurrentUtcDate() {
        SimpleDateFormat sdf = new SimpleDateFormat(DATEFORMAT);
        sdf.setTimeZone(TimeZone.getTimeZone(UTC_TIMEZONE_CODE));
        String utcTime = sdf.format(new Date());

        Date dateToReturn = null;
        SimpleDateFormat dateFormat = new SimpleDateFormat(DATEFORMAT);
        try {//from   ww w  .  j a  va 2  s  .  co m
            dateToReturn = dateFormat.parse(utcTime);
        } catch (ParseException e) {
            e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
        }

        return dateToReturn;
    }
}

Related

  1. getCurrentTimeString(String format)
  2. getCurrentTimeString(String pattern)
  3. getCurrentToNextDaySecond()
  4. getCurrentUnixTime()
  5. getCurrentUTCDate()
  6. getCurrentUTCSeconds(Date current)
  7. getCurrentUTCString()
  8. getCurrentUTCTime()
  9. getCurrentUTCTimeAsString()