Java Today getToday(String time)

Here you can find the source of getToday(String time)

Description

get Today

License

Apache License

Declaration

public static Date getToday(String time) 

Method Source Code


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

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

public class Main {
    public static final String DEFAULT_FORMAT_DATE = "yyyy-MM-dd";
    public static final String DEFAULT_FORMAT_DATETIME = "yyyy-MM-dd HH:mm:ss";

    public static Date getToday(String time) {
        String today = todayStr();
        return getDateTime(today + " " + time, DEFAULT_FORMAT_DATETIME);
    }//from  w w  w. jav  a2 s.c om

    public static String todayStr() {
        return currentDateStr();
    }

    public static Date getDateTime(String dateString, String format) {
        SimpleDateFormat sf = new SimpleDateFormat(format);
        Date date = null;
        try {
            date = sf.parse(dateString);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }

    public static Date getDateTime(String dateTimeString) {
        return getDateTime(dateTimeString, DEFAULT_FORMAT_DATETIME);
    }

    public static String currentDateStr() {
        return toDateString(new Date(), DEFAULT_FORMAT_DATE);
    }

    public static String toDateString(Date date, String format) {
        SimpleDateFormat sf = new SimpleDateFormat(format);
        return sf.format(date);
    }
}

Related

  1. getToDay(boolean withTime)
  2. getToday(int hour, int minute, int second)
  3. getToday(String datePattern)
  4. getToday(String format)
  5. getToday(String formatString)
  6. getTodayAsLong()
  7. getTodayAsSecond()
  8. getTodayDate()
  9. getTodayDate()