Java Second Format getToSecond()

Here you can find the source of getToSecond()

Description

HH:mm:ss

License

Apache License

Declaration

public static String getToSecond() 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.text.DateFormat;

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

import java.util.TimeZone;

public class Main {
    public final static String DEFAULT_DATE_FORMAT = "yyyy-MM-dd";

    /**//from  w  w w. ja va  2s  .  co m
     * HH:mm:ss
     * 
     */
    public static String getToSecond() {
        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
        Date logonDate = Calendar.getInstance().getTime();
        return sdf.format(logonDate);
    }

    public static Date getTime() {
        return Calendar.getInstance().getTime();
    }

    public static Date getTime(int field, int diff) {
        Calendar c = Calendar.getInstance();
        c.add(field, diff);
        return c.getTime();
    }

    /**
     * get time of dstTimeZone from time of srcTimeZone
     * 
     * @param time
     * @param srcTimeZone
     * @param dstTimeZone
     * @return Data
     */
    private static Date getTime(Date time, TimeZone srcTimeZone, TimeZone dstTimeZone) {
        if (time == null)
            return null;
        DateFormat df = new SimpleDateFormat(DEFAULT_DATE_FORMAT);
        df.setTimeZone(dstTimeZone);
        String gmtTime = df.format(time); // convert current time to gmt time.
        df.setTimeZone(srcTimeZone);
        try {
            return df.parse(gmtTime); // gmt time to date
        } catch (ParseException e) {
            return time;
        }

    }

    public static Date parse(String date, String format) throws ParseException {
        if (date == null)
            return null;

        SimpleDateFormat fmt = new SimpleDateFormat(format);

        return fmt.parse(date);
    }
}

Related

  1. getSecondsFormatter()
  2. getSecondsSince(String rfc1123Date)
  3. getStringFromNanoSeconds(final long nanoSeconds, final long format)
  4. getThisSecondTime()
  5. getTimeSecondInteger(Date date)
  6. humanDateToSeconds(String date)
  7. parseLongToString(long millsSeconds)
  8. parseNoSecondFormat(String sDate)
  9. printElapsedSeconds(long start)