Java Day of getTwoDay(String sj1, String sj2)

Here you can find the source of getTwoDay(String sj1, String sj2)

Description

get Two Day

License

Open Source License

Declaration


public static String getTwoDay(String sj1, String sj2) 

Method Source Code

//package com.java2s;

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

public class Main {

    public static String getTwoDay(String sj1, String sj2) {
        SimpleDateFormat myFormatter = new SimpleDateFormat("yyyy-MM-dd");
        long day = 0;
        try {//from w  ww  .  java  2 s .c  o m
            java.util.Date date = myFormatter.parse(sj1);
            java.util.Date mydate = myFormatter.parse(sj2);
            day = (date.getTime() - mydate.getTime()) / (24 * 60 * 60 * 1000);
        } catch (Exception e) {
            return "";
        }
        return day + "";

    }

    public static String getTime() {

        Date currentTime = new Date();

        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        String dateString = formatter.format(currentTime);

        String min;

        min = dateString.substring(14, 16);

        return min;

    }

    public static String format(java.util.Date date, String format, Calendar calendar) {
        String result = "";
        try {
            if (date != null) {
                java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(format);
                if (calendar != null) {
                    sdf.setCalendar(calendar);
                }
                result = sdf.format(date);
            }
        } catch (Exception e) {
        }

        return result;
    }

    public static String format(java.util.Date date, String format) {
        return format(date, format, null);
    }

    public static String format(long times, String format) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(times);
        return format(calendar.getTime(), format);
    }
}

Related

  1. getTheDayBefore(Date date)
  2. getThursday(String date)
  3. getTimeOfDaySeconds()
  4. getTimestamp(String format, Integer daysInFuture)
  5. getTwoDay(String sj1, String sj2)
  6. getTwoDay2String(String startDate, String endDate, Format format)
  7. getWorkingDay(Calendar d1, Calendar d2)
  8. getYesday()
  9. getYYYY_MM_DD(int offsetDays)