Java Time Now getCurrDateTime()

Here you can find the source of getCurrDateTime()

Description

get Curr Date Time

License

Apache License

Declaration

public static Date getCurrDateTime() 

Method Source Code

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

import java.text.ParsePosition;
import java.text.SimpleDateFormat;

public class Main {
    public static Date getCurrDateTime() {
        return stringToDate(getCurrTime());
        //        return new Date(System.currentTimeMillis());
    }/*from w  w  w .  ja  v  a2 s  . co  m*/

    public static Date stringToDate(String dateString) {
        String sf = "yyyy-MM-dd HH:mm:ss";
        Date dt = stringToDate(dateString, sf);
        return dt;
    }

    public static Date stringToDate(String dateString, String sf) {
        ParsePosition pos = new ParsePosition(0);
        SimpleDateFormat sdf = new SimpleDateFormat(sf);
        Date dt = sdf.parse(dateString, pos);
        return dt;
    }

    public static String getCurrTime() {
        Date date_time = new Date();
        return FormatDate(date_time, "yyyy-MM-dd HH:mm:ss");
    }

    public static String FormatDate(Date date, String sf) {
        if (date == null)
            return "";
        SimpleDateFormat dateformat = new SimpleDateFormat(sf);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        if (date.getHours() == 0)
            return sdf.format(date);
        else
            return dateformat.format(date);
    }
}

Related

  1. get_cur_datetime()
  2. getCurDateBefore(long time)
  3. getCurDateTime()
  4. getCurDateTIme()
  5. getCurentTimeDirsPath()
  6. getCurrSysTime()
  7. getCurrTime()
  8. getCurrTime()
  9. getCurTime()