Java Date Now getCurrentUTCTime()

Here you can find the source of getCurrentUTCTime()

Description

get Current UTC Time

License

Open Source License

Declaration

public static Date getCurrentUTCTime() 

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";

    public static Date getCurrentUTCTime() {
        try {//  w  ww.j  ava 2  s . c  o  m
            return stringDateToDate(getCurrentUTCTimeAsString());
        } catch (ParseException e) {
            e.printStackTrace();

        }
        return null;
    }

    public static Date stringDateToDate(String StrDate) throws ParseException {
        Date dateToReturn = null;
        SimpleDateFormat dateFormat = new SimpleDateFormat(DATEFORMAT);

        try {
            dateToReturn = (Date) dateFormat.parse(StrDate);
        } catch (ParseException e) {
            e.printStackTrace();
        }

        return dateToReturn;
    }

    public static String getCurrentUTCTimeAsString() {
        final SimpleDateFormat sdf = new SimpleDateFormat(DATEFORMAT);
        sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
        final String utcTime = sdf.format(new Date());

        return utcTime;
    }

    public static String format(Date date) {
        SimpleDateFormat dateFormat = new SimpleDateFormat(DATEFORMAT);
        return dateFormat.format(date);
    }
}

Related

  1. getCurrentUnixTime()
  2. getCurrentUTCDate()
  3. getCurrentUtcDate()
  4. getCurrentUTCSeconds(Date current)
  5. getCurrentUTCString()
  6. getCurrentUTCTimeAsString()
  7. getCurrentWeekDay(Date date, int day)
  8. getCurrentWeekDays()
  9. getCurrentWeekFirst()