Java SQL Time Calculate getNextDateTimeStr(String format)

Here you can find the source of getNextDateTimeStr(String format)

Description

get Next Date Time Str

License

Open Source License

Declaration

public static String getNextDateTimeStr(String format) 

Method Source Code


//package com.java2s;
import java.util.Calendar;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;

public class Main {

    public static String getNextDateTimeStr(String format) {
        Calendar calendar = Calendar.getInstance();

        long longDate = (calendar.getTime()).getTime() + (1000 * 60 * 60 * 24 * 1);
        java.util.Date date = new java.util.Date(longDate);
        calendar.setTime(date);/*  www .  j  a v a  2s  . c  o m*/

        return toDateTimeString(calendar.getTime(), format);
    }

    public static String toDateTimeString(java.util.Date date) {
        if (date == null)
            return "";

        String dateString = toDateString(date);
        String timeString = toTimeString(date);

        if (dateString == null || timeString == null)
            return "";

        return dateString + " " + timeString;
    }

    public static String toDateTimeString(Calendar calendar) {
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(calendar.getTime());
    }

    public static String toDateTimeString(Calendar calendar, String format) {
        return toDateTimeString(calendar.getTime(), format);
    }

    public static String toDateTimeString(long datetime) {
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new java.util.Date(datetime));
    }

    public static String toDateTimeString(long datetime, String format) {
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        return sdf.format(new java.util.Date(datetime));
    }

    public static String toDateTimeString(java.util.Date date, String format) {
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        return sdf.format(date);
    }

    public static String toDateTimeString(Timestamp time) {
        long datetime = time.getTime();
        return toDateTimeString(datetime);
    }

    public static String toDateTimeString(java.sql.Date date) {
        long datetime = date.getTime();
        return toDateTimeString(datetime);
    }

    public static String toDateString(java.util.Date date, String spe) {
        if (date == null)
            return "";

        Calendar calendar = Calendar.getInstance();

        calendar.setTime(date);
        int month = calendar.get(Calendar.MONTH) + 1;
        int day = calendar.get(Calendar.DAY_OF_MONTH);
        int year = calendar.get(Calendar.YEAR);

        String monthStr = "" + month;
        String dayStr = "" + day;
        String yearStr = "" + year;

        if (month < 10)
            monthStr = "0" + month;

        if (day < 10)
            dayStr = "0" + day;

        return yearStr + spe + monthStr + spe + dayStr;
    }

    public static String toDateString(java.util.Date date) {
        return toDateString(date, "-");
    }

    public static String toDateString(Calendar calendar) {
        return new SimpleDateFormat("yyyy-MM-dd").format(calendar.getTime());
    }

    public static String toTimeString(java.util.Date date) {
        if (date == null)
            return "";

        Calendar calendar = Calendar.getInstance();

        calendar.setTime(date);
        return toTimeString(calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE),
                calendar.get(Calendar.SECOND));
    }

    public static String toTimeString(int hour, int minute, int second) {
        String hourStr = "" + hour;
        String minuteStr = "" + minute;
        String secondStr = "" + second;

        if (hour < 10)
            hourStr = "0" + hour;

        if (minute < 10)
            minuteStr = "0" + minute;

        if (second < 10)
            secondStr = "0" + second;

        return hourStr + ":" + minuteStr + ":" + secondStr;
    }
}

Related

  1. getMidNightTime()
  2. getMinute(Time time)
  3. getMonth(String dateTime)
  4. getMonth(String dateTime)
  5. getNewFileList(String path, String mintime)
  6. getNurseCoverageEndTime(Time startTime, Time shiftLength)
  7. getPreviousDateTimeString(String format)