Java Date Now getCurrentUTCSeconds(Date current)

Here you can find the source of getCurrentUTCSeconds(Date current)

Description

get Current UTC Seconds

License

Open Source License

Declaration

@SuppressWarnings("deprecation")
    public static int getCurrentUTCSeconds(Date current) 

Method Source Code

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

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Main {
    private static SimpleDateFormat stringDateTimeFormat = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
    private static final SimpleDateFormat defaultFormater = new SimpleDateFormat("yyyyMMdd");
    private static final SimpleDateFormat customizedFormater = new SimpleDateFormat("yyyyMMdd");

    @SuppressWarnings("deprecation")
    public static int getCurrentUTCSeconds() {
        Date _current = Calendar.getInstance().getTime();
        String dt = stringDateTimeFormat.format(_current);
        String tempDateTime[] = dt.split("-");
        int yy = Integer.parseInt(tempDateTime[0]);
        int MM = Integer.parseInt(tempDateTime[1]);
        int dd = Integer.parseInt(tempDateTime[2]);
        int HH = Integer.parseInt(tempDateTime[3]);
        int mm = Integer.parseInt(tempDateTime[4]);
        int ss = Integer.parseInt(tempDateTime[5]);
        return (int) (Date.UTC(yy, MM, dd, HH, mm, ss) / 1000 % 86400);
    }//from w w  w . j av a  2  s.c  o  m

    @SuppressWarnings("deprecation")
    public static int getCurrentUTCSeconds(Date current) {
        String dt = stringDateTimeFormat.format(current);
        String tempDateTime[] = dt.split("-");
        int yy = Integer.parseInt(tempDateTime[0]);
        int MM = Integer.parseInt(tempDateTime[1]);
        int dd = Integer.parseInt(tempDateTime[2]);
        int HH = Integer.parseInt(tempDateTime[3]);
        int mm = Integer.parseInt(tempDateTime[4]);
        int ss = Integer.parseInt(tempDateTime[5]);
        return (int) (Date.UTC(yy, MM, dd, HH, mm, ss) / 1000 % 86400);
    }

    public static String getTime() {
        Date currentTime = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
        return formatter.format(currentTime);
    }

    public static String format(Date date, String pattern) {
        synchronized (customizedFormater) {
            if (null != pattern && !"".equals(pattern.trim())) {
                customizedFormater.applyPattern(pattern);
            } else {
                throw new IllegalArgumentException("pattern can not be empty");
            }
            return customizedFormater.format(date);
        }
    }

    public static String format(Date date) {
        synchronized (defaultFormater) {
            return defaultFormater.format(date);
        }
    }
}

Related

  1. getCurrentTimeString(String pattern)
  2. getCurrentToNextDaySecond()
  3. getCurrentUnixTime()
  4. getCurrentUTCDate()
  5. getCurrentUtcDate()
  6. getCurrentUTCString()
  7. getCurrentUTCTime()
  8. getCurrentUTCTimeAsString()
  9. getCurrentWeekDay(Date date, int day)