java 当天日期 dateutil_Java时间日期DateUtil

import java.text.ParseException;

import java.text.SimpleDateFormat;

import java.util.Calendar;

import java.util.Date;

public class DateUtil {

private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

/*

获取昨天的日期

*/

public static Date getYesterday(Date date) {

Calendar cal = Calendar.getInstance();

cal.setTime(date);

cal.add(Calendar.DATE,-1);

Date yesterday = cal.getTime();

return yesterday;

}

/*

获取传入时间的日份

*/

public static int getDay(Date date) {

Calendar cal = Calendar.getInstance();

cal.setTime(date);

return cal.get(Calendar.DATE);

}

/**

* 获取传入时间的月份

*/

public static int getMonth(Date date) {

Calendar cal = Calendar.getInstance();

cal.setTime(date);

return cal.get(Calendar.MONTH) + 1;

}

/**

* 获取传入时间的季度

*/

public static int getQuarter(Date date) {

int month = getMonth(date);

if (month <= 3)

return 1;

else if (month <= 6)

return 2;

else if (month <= 9)

return 3;

else

return 4;

}

/**

* 获取传入时间的年份

*/

public static int getYear(Date date) {

Calendar cal = Calendar.getInstance();

cal.setTime(date);

return cal.get(Calendar.YEAR);

}

/**

* 获取传入时间月份天数

*/

public static int getCurrentMonthDay(Date date) {

Calendar cal = Calendar.getInstance();

cal.setTime(date);

cal.set(Calendar.DATE, 1);

cal.roll(Calendar.DATE, -1);

return cal.get(Calendar.DATE);

}

/**

* 获得传入时间为是星期几

*/

public static int getWeekDay(Date date) {

Calendar c = Calendar.getInstance();

c.setTime(date);

int weekDay = c.get(Calendar.DAY_OF_WEEK);

return weekDay - 1;

}

/*

获取所在周指定星期几的日期Date

*/

public static Date getWeekDayDate(Date date, int num) {

Calendar c = Calendar.getInstance();

c.setTime(date);

switch (num) {

case 1:

c.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);

break;

case 2:

c.set(Calendar.DAY_OF_WEEK, Calendar.TUESDAY);

break;

case 3:

c.set(Calendar.DAY_OF_WEEK, Calendar.WEDNESDAY);

break;

case 4:

c.set(Calendar.DAY_OF_WEEK, Calendar.THURSDAY);

break;

case 5:

c.set(Calendar.DAY_OF_WEEK, Calendar.FRIDAY);

break;

case 6:

c.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY);

break;

case 7:

// c.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);

int weekday = c.get(Calendar.DAY_OF_WEEK);

c.add(Calendar.DATE, 8 - weekday);

break;

}

return c.getTime();

}

/*

获取传入时间所在周第一天,周一

*/

public static Date getFirstWeekDay(Date date) {

Calendar c = Calendar.getInstance();

c.setTime(date);

try {

int weekday = c.get(Calendar.DAY_OF_WEEK) - 2;

c.add(Calendar.DATE, -weekday);

} catch (Exception e) {

e.printStackTrace();

}

return c.getTime();

}

/*

获取传入时间所在周最后一天,周日

*/

public static Date getLastWeekDay(Date date) {

Calendar c = Calendar.getInstance();

c.setTime(date);

try {

int weekday = c.get(Calendar.DAY_OF_WEEK);

c.add(Calendar.DATE, 8 - weekday);

} catch (Exception e) {

e.printStackTrace();

}

return c.getTime();

}

/**

* 根据日期获取月初第一天

*/

public static Date getFirstMonthDay(Date date) {

Calendar cal = Calendar.getInstance();// 获取当前日期

cal.setTime(date);

cal.add(Calendar.MONTH, 0);

cal.set(Calendar.DAY_OF_MONTH, 1);

return cal.getTime();

}

/**

* 根据日期获取月末最后一天

*/

public static Date getLastMonthDay(Date date) {

Calendar cal = Calendar.getInstance();

cal.setTime(date);

cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));

return cal.getTime();

}

/*

根据日期获取所在季度的第一天

*/

public static Date getFirstQuarterDay(Date date) {

Calendar cal = Calendar.getInstance();

cal.setTime(date);

int currentMonth = cal.get(Calendar.MONTH) + 1;

try {

if (currentMonth >= 1 && currentMonth <= 3)

cal.set(Calendar.MONTH, 0);

else if (currentMonth >= 4 && currentMonth <= 6)

cal.set(Calendar.MONTH, 3);

else if (currentMonth >= 7 && currentMonth <= 9)

cal.set(Calendar.MONTH, 6);

else if (currentMonth >= 10 && currentMonth <= 12)

cal.set(Calendar.MONTH, 9);

cal.set(Calendar.DAY_OF_MONTH, cal.getActualMinimum(Calendar.DAY_OF_MONTH));

} catch (Exception e) {

e.printStackTrace();

}

return cal.getTime();

}

/*

根据日期获取所在季度的最后一天

*/

public static Date getLastQuarterDay(Date date) {

Calendar cal = Calendar.getInstance();

cal.setTime(date);

int currentMonth = cal.get(Calendar.MONTH) + 1;

try {

if (currentMonth >= 1 && currentMonth <= 3)

cal.set(Calendar.MONTH, 2);

else if (currentMonth >= 4 && currentMonth <= 6)

cal.set(Calendar.MONTH, 5);

else if (currentMonth >= 7 && currentMonth <= 9)

cal.set(Calendar.MONTH, 8);

else if (currentMonth >= 10 && currentMonth <= 12)

cal.set(Calendar.MONTH, 11);

cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));

} catch (Exception e) {

e.printStackTrace();

}

return cal.getTime();

}

/*

所在年前/后半年开始日期

*/

public static Date getHalfYearStartTime(Date date) {

Calendar c = Calendar.getInstance();

c.setTime(date);

int currentMonth = c.get(Calendar.MONTH) + 1;

if (currentMonth >= 1 && currentMonth <= 6) {

c.set(Calendar.MONTH, 0);

} else if (currentMonth >= 7 && currentMonth <= 12) {

c.set(Calendar.MONTH, 6);

}

c.set(Calendar.DATE, 1);

return c.getTime();

}

/**

所在年前/后半年的结束时间

*/

public static Date getHalfYearEndTime(Date date) {

Calendar c = Calendar.getInstance();

c.setTime(date);

int currentMonth = c.get(Calendar.MONTH) + 1;

if (currentMonth >= 1 && currentMonth <= 6) {

c.set(Calendar.MONTH, 5);

c.set(Calendar.DATE, 30);

} else if (currentMonth >= 7 && currentMonth <= 12) {

c.set(Calendar.MONTH, 11);

c.set(Calendar.DATE, 31);

}

return c.getTime();

}

/**

* 根据日期获取年第一天

*/

public static Date getYearFirstDay(Date date){

Calendar calendar = Calendar.getInstance();

calendar.setTime(date);

int year=calendar.get(Calendar.YEAR);

Calendar cd = Calendar.getInstance();

cd.clear();

cd.set(Calendar.YEAR, year);

cd.roll(Calendar.DAY_OF_YEAR,0);

Date currYearLast = cd.getTime();

return currYearLast;

}

/*

获取当月指定天数日期

*/

public static Date getDateByDay(Date date, int day) {

Calendar cal = Calendar.getInstance();

cal.setTime(date);

cal.set(Calendar.DATE, day);

return cal.getTime();

}

/*

获取上月指定天数日期

*/

public static Date getLastMonthByDay(Date date, int day) {

Calendar cal = Calendar.getInstance();

cal.setTime(date);

int month = cal.get(Calendar.MONTH);

cal.set(Calendar.MONTH, month - 1);

cal.set(Calendar.DATE, day);

return cal.getTime();

}

/**

* 获取传入时间所在季度总天数

*/

public static int getCurrentQuarterDay(Date date) {

Date firstDayDate = getFirstQuarterDay(date);

Date lastDayDate = getLastQuarterDay(date);

int day = (int) ((lastDayDate.getTime() - firstDayDate.getTime()) / (24*3600*1000) + 1);

return day;

}

/*

判断日期是否为周日

*/

public static boolean isWeekEnd(Date date) {

Calendar calendar = Calendar.getInstance();

calendar.setTime(date);

if(calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY){

return true;

} else{

return false;

}

}

/*

判断日期是否为月末

*/

public static boolean isMonthEnd(Date date) {

Calendar calendar = Calendar.getInstance();

calendar.setTime(date);

int getDay = calendar.get(Calendar.DAY_OF_MONTH);

if(getDay == calendar.getActualMaximum(Calendar.DAY_OF_MONTH)){

return true;

}else{

return false;

}

}

/*

判断日期是否为季末(最后一天)

*/

public static boolean isQuarterEnd(Date date) {

Calendar c = Calendar.getInstance();

c.setTime(date);

int currentMonth = c.get(Calendar.MONTH) + 1;

Date dt = null;

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

try {

if (currentMonth >= 1 && currentMonth <= 3) {

c.set(Calendar.MONTH, 2);

c.set(Calendar.DATE, 31);

} else if (currentMonth >= 4 && currentMonth <= 6) {

c.set(Calendar.MONTH, 5);

c.set(Calendar.DATE, 30);

} else if (currentMonth >= 7 && currentMonth <= 9) {

c.set(Calendar.MONTH, 8);

c.set(Calendar.DATE, 30);

} else if (currentMonth >= 10 && currentMonth <= 12) {

c.set(Calendar.MONTH, 11);

c.set(Calendar.DATE, 31);

}

dt = sdf.parse(sdf.format(c.getTime()));

} catch (Exception e) {

e.printStackTrace();

}

if (date.compareTo(dt) == 0) {

return true;

} else {

return false;

}

}

/*

据日期获取去年年末

*/

public static Date getLastYearLastDay(Date date){

Calendar calendar = Calendar.getInstance();

calendar.setTime(date);

int year=calendar.get(Calendar.YEAR)-1;

Calendar cd = Calendar.getInstance();

cd.clear();

cd.set(Calendar.YEAR, year);

cd.roll(Calendar.DAY_OF_YEAR, -1);

Date currYearLast = cd.getTime();

return currYearLast;

}

/**

* 属于本年第几天

*/

public static int getYearDayIndex(Date date) {

Calendar calendar = Calendar.getInstance();

calendar.setFirstDayOfWeek(Calendar.MONDAY);

calendar.setTime(date);

return calendar.get(Calendar.DAY_OF_YEAR);

}

/**

* 属于本年第几周

*/

public static int getYearWeekIndex(Date date) {

Calendar calendar = Calendar.getInstance();

calendar.setFirstDayOfWeek(Calendar.MONDAY);

calendar.setTime(date);

return calendar.get(Calendar.WEEK_OF_YEAR);

}

/*

获取两个日期间的天数,直接传入Date

*/

public static Long getDayByDates(Date startDate, Date endDate) {

Long day = (endDate.getTime() - startDate.getTime()) / (24 * 60 * 60 * 1000);

return day;

}

/*

获取两个日期间的天数,直接传入StrDate

*/

public static Long getDayByStrDates(String startStrDate, String endStrDate) throws ParseException {

Date startDate = sdf.parse(startStrDate);

Date endDate = sdf.parse(endStrDate);

Long day = (endDate.getTime() - startDate.getTime()) / (24 * 60 * 60 * 1000);

return day;

}

/**

* 判断是否闰年

* 详细设计: 1.被400整除是闰年,否则: 2.不能被4整除则不是闰年 3.能被4整除同时不能被100整除则是闰年

* 3.能被4整除同时能被100整除则不是闰年

*/

public static boolean isLeapYear(Date date) {

Calendar cal = Calendar.getInstance();

cal.setTime(date);

int year = cal.get(Calendar.YEAR);

if ((year % 400) == 0) {

return true;

} else if ((year % 4) == 0) {

if ((year % 100) == 0) {

return false;

} else {

return true;

}

} else {

return false;

}

}

public static void main(String[] args) throws ParseException {

Date date = new Date();

System.out.println("前一天日期为:" + sdf.format(getYesterday(date)));

System.out.println("该日期的日份:" + getDay(date));

System.out.println("该日期的月份:" + getMonth(date));

System.out.println("该日期的季度:" + getQuarter(date));

System.out.println("该日期的年份:" + getYear(date));

System.out.println("所在月总天数:" + getCurrentMonthDay(date));

System.out.println("所在季度总天数:" + getCurrentQuarterDay(date));

System.out.println("该日期为本周星期:" + getWeekDay(date));

System.out.println("所在周的星期天的日期:" + sdf.format(getWeekDayDate(date, 7)));

System.out.println("所在周第一天日期:" + sdf.format(getFirstWeekDay(date)));

System.out.println("所在周最后一天日期:" + sdf.format(getLastWeekDay(date)));

System.out.println("所在月第一天日期:" + sdf.format(getFirstMonthDay(date)));

System.out.println("所在月最后一天日期:" + sdf.format(getLastMonthDay(date)));

System.out.println("所在季度第一天日期:" + sdf.format(getFirstQuarterDay(date)));

System.out.println("所在季度最后一天日期:" + sdf.format(getLastQuarterDay(date)));

System.out.println("所在年前/后半年开始日期:" + sdf.format(getHalfYearStartTime(date)));

System.out.println("所在年前/后半年结束日期:" + sdf.format(getHalfYearEndTime(date)));

System.out.println("所在年第一天日期:" + sdf.format(getYearFirstDay(date)));

System.out.println("所在月指定天数日期:" + sdf.format(getDateByDay(date, 10)));

System.out.println("上月指定天数日期:" + sdf.format(getLastMonthByDay(date, 10)));

System.out.println("是否为周日:" + isWeekEnd(date));

System.out.println("是否为月末:" + isMonthEnd(date));

System.out.println("是否为季末:" + isQuarterEnd(date));

System.out.println("去年最后一天日期:" + sdf.format(getLastYearLastDay(date)));

System.out.println("属于本年第几天:" + getYearDayIndex(date));

System.out.println("属于本年第几周:" + getYearWeekIndex(date));

System.out.println("两个日期的间隔天数:" + getDayByDates(sdf.parse("2019-10-28"), date));

System.out.println("两个日期的间隔天数:" + getDayByStrDates("2019-10-23", "2019-10-30"));

System.out.println("是否为闰年:" + isLeapYear(date));

}

}

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
package com.hexiang.utils; /** * @(#)DateUtil.java * * * @author kidd * @version 1.00 2007/8/8 */ import java.util.*; import java.text.*; import java.sql.Timestamp; public class DateUtils { /** * 时间范围:年 */ public static final int YEAR = 1; /** * 时间范围:季度 */ public static final int QUARTER = 2; /** * 时间范围:月 */ public static final int MONTH = 3; /** * 时间范围:旬 */ public static final int TENDAYS = 4; /** * 时间范围:周 */ public static final int WEEK = 5; /** * 时间范围:日 */ public static final int DAY = 6; /* 基准时间 */ private Date fiducialDate = null; private Calendar cal = null; private DateUtils(Date fiducialDate) { if (fiducialDate != null) { this.fiducialDate = fiducialDate; } else { this.fiducialDate = new Date(System.currentTimeMillis()); } this.cal = Calendar.getInstance(); this.cal.setTime(this.fiducialDate); this.cal.set(Calendar.HOUR_OF_DAY, 0); this.cal.set(Calendar.MINUTE, 0); this.cal.set(Calendar.SECOND, 0); this.cal.set(Calendar.MILLISECOND, 0); this.fiducialDate = this.cal.getTime(); } /** * 获取DateHelper实例 * * @param fiducialDate * 基准时间 * @return Date */ public static DateUtils getInstance(Date fiducialDate) { return new DateUtils(fiducialDate); } /** * 获取DateHelper实例, 使用当前时间作为基准时间 * * @return Date */ public static DateUtils getInstance() { return new DateUtils(null); } /** * 获取年的第一天 * * @param offset * 偏移量 * @return Date */ public Date getFirstDayOfYear(int offset) { cal.setTime(this.fiducialDate); cal.set(Calendar.YEAR, cal.get(Calendar.YEAR) + offset); cal.set(Calendar.MONTH, Calendar.JANUARY); cal.set(Calendar.DAY_OF_MONTH, 1); return cal.getTime(); } /** * 获取年的最后一天 * * @param offset * 偏移量 * @return Date */ public Date getLastDayOfYear(int offset) { cal.setTime(this.fiducialDate); cal.set(Calendar.YEAR, cal.get(Calendar.YEAR) + offset); cal.set(Calendar.MONTH, Calendar.DECEMBER); cal.set(Calendar.DAY_OF_MONTH, 31); return cal.getTime(); } /** * 获取季度的第一天 * * @param offset * 偏移量 * @return Date */ public Date getFirstDayOfQuarter(int offset) { cal.setTime(this.fiducialDate); cal.add(Calendar.MONTH, offset * 3); int mon = cal.get(Calendar.MONTH); if (mon >= Calendar.JANUARY && mon = Calendar.APRIL && mon = Calendar.JULY && mon = Calendar.OCTOBER && mon = Calendar.JANUARY && mon = Calendar.APRIL && mon = Calendar.JULY && mon = Calendar.OCTOBER && mon = 21) { day = 21; } else if (day >= 11) { day = 11; } else { day = 1; } if (offset > 0) { day = day + 10 * offset; int monOffset = day / 30; day = day % 30; cal.add(Calendar.MONTH, monOffset); cal.set(Calendar.DAY_OF_MONTH, day); } else { int monOffset = 10 * offset / 30; int dayOffset = 10 * offset % 30; if ((day + dayOffset) > 0) { day = day + dayOffset; } else { monOffset = monOffset - 1; day = day - dayOffset - 10; } cal.add(Calendar.MONTH, monOffset); cal.set(Calendar.DAY_OF_MONTH, day); } return cal.getTime(); } /** * 获取旬的最后一天 * * @param offset * 偏移量 * @return Date */ public Date getLastDayOfTendays(int offset) { Date date = getFirstDayOfTendays(offset + 1); cal.setTime(date); cal.add(Calendar.DAY_OF_MONTH, -1); return cal.getTime(); } /** * 获取周的第一天(MONDAY) * * @param offset * 偏移量 * @return Date */ public Date getFirstDayOfWeek(int offset) { cal.setTime(this.fiducialDate); cal.add(Calendar.DAY_OF_MONTH, offset * 7); cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); return cal.getTime(); } /** * 获取周的最后一天(SUNDAY) * * @param offset * 偏移量 * @return Date */ public Date getLastDayOfWeek(int offset) { cal.setTime(this.fiducialDate); cal.add(Calendar.DAY_OF_MONTH, offset * 7); cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); cal.add(Calendar.DAY_OF_MONTH, 6); return cal.getTime(); } /** * 获取指定时间范围的第一天 * * @param dateRangeType * 时间范围类型 * @param offset * 偏移量 * @return Date */ public Date getFirstDate(int dateRangeType, int offset) { return null; } /** * 获取指定时间范围的最后一天 * * @param dateRangeType * 时间范围类型 * @param offset * 偏移量 * @return Date */ public Date getLastDate(int dateRangeType, int offset) { return null; } /** * 根据日历的规则,为基准时间添加指定日历字段的时间量 * * @param field * 日历字段, 使用Calendar类定义的日历字段常量 * @param offset * 偏移量 * @return Date */ public Date add(int field, int offset) { cal.setTime(this.fiducialDate); cal.add(field, offset); return cal.getTime(); } /** * 根据日历的规则,为基准时间添加指定日历字段的单个时间单元 * * @param field * 日历字段, 使用Calendar类定义的日历字段常量 * @param up * 指定日历字段的值的滚动方向。true:向上滚动 / false:向下滚动 * @return Date */ public Date roll(int field, boolean up) { cal.setTime(this.fiducialDate); cal.roll(field, up); return cal.getTime(); } /** * 把字符串转换为日期 * * @param dateStr * 日期字符串 * @param format * 日期格式 * @return Date */ public static Date strToDate(String dateStr, String format) { Date date = null; if (dateStr != null && (!dateStr.equals(""))) { DateFormat df = new SimpleDateFormat(format); try { date = df.parse(dateStr); } catch (ParseException e) { e.printStackTrace(); } } return date; } /** * 把字符串转换为日期日期的格式为yyyy-MM-dd HH:ss * * @param dateStr * 日期字符串 * @return Date */ public static Date strToDate(String dateStr) { Date date = null; if (dateStr != null && (!dateStr.equals(""))) { if (dateStr.matches("\\d{4}-\\d{1,2}-\\d{1,2}")) { dateStr = dateStr + " 00:00"; } else if (dateStr.matches("\\d{4}-\\d{1,2}-\\d{1,2} \\d{1,2}")) { dateStr = dateStr + ":00"; } else { System.out.println(dateStr + " 格式不正确"); return null; } DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:ss"); try { date = df.parse(dateStr); } catch (ParseException e) { e.printStackTrace(); } } return date; } /** * 把日期转换为字符串 * * @param date * 日期实例 * @param format * 日期格式 * @return Date */ public static String dateToStr(Date date, String format) { return (date == null) ? "" : new SimpleDateFormat(format).format(date); } public static String dateToStr(Date date) { return (date == null) ? "" : new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(date); } /** * 取得当前日期 年-月-日 * * @return Date */ public static String getCurrentDate() { DateFormat f = new SimpleDateFormat("yyyy-MM-dd"); return f.format(Calendar.getInstance().getTime()); } public static void main(String[] args) { DateUtils dateHelper = DateUtils.getInstance(); /* Year */ for (int i = -5; i <= 5; i++) { System.out.println("FirstDayOfYear(" + i + ") = " + dateHelper.getFirstDayOfYear(i)); System.out.println("LastDayOfYear(" + i + ") = " + dateHelper.getLastDayOfYear(i)); } /* Quarter */ for (int i = -5; i <= 5; i++) { System.out.println("FirstDayOfQuarter(" + i + ") = " + dateHelper.getFirstDayOfQuarter(i)); System.out.println("LastDayOfQuarter(" + i + ") = " + dateHelper.getLastDayOfQuarter(i)); } /* Month */ for (int i = -5; i <= 5; i++) { System.out.println("FirstDayOfMonth(" + i + ") = " + dateHelper.getFirstDayOfMonth(i)); System.out.println("LastDayOfMonth(" + i + ") = " + dateHelper.getLastDayOfMonth(i)); } /* Week */ for (int i = -5; i <= 5; i++) { System.out.println("FirstDayOfWeek(" + i + ") = " + dateHelper.getFirstDayOfWeek(i)); System.out.println("LastDayOfWeek(" + i + ") = " + dateHelper.getLastDayOfWeek(i)); } /* Tendays */ for (int i = -5; i <= 5; i++) { System.out.println("FirstDayOfTendays(" + i + ") = " + dateHelper.getFirstDayOfTendays(i)); System.out.println("LastDayOfTendays(" + i + ") = " + dateHelper.getLastDayOfTendays(i)); } } /** * 取当前日期的字符串形式,"XXXX年XX月XX日" * * @return java.lang.String */ public static String getPrintDate() { String printDate = ""; Calendar calendar = Calendar.getInstance(); calendar.setTime(new Date()); printDate += calendar.get(Calendar.YEAR) + "年"; printDate += (calendar.get(Calendar.MONTH) + 1) + "月"; printDate += calendar.get(Calendar.DATE) + "日"; return printDate; } /** * 将指定的日期字符串转化为日期对象 * * @param dateStr * 日期字符串 * @return java.util.Date */ public static Date getDate(String dateStr, String format) { if (dateStr == null) { return new Date(); } if (format == null) { format = "yyyy-MM-dd"; } SimpleDateFormat sdf = new SimpleDateFormat(format); try { Date date = sdf.parse(dateStr); return date; } catch (Exception e) { return null; } } /** * 从指定Timestamp中得到相应的日期的字符串形式 日期"XXXX-XX-XX" * * @param dateTime * @return 、String */ public static String getDateFromDateTime(Timestamp dateTime) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); return sdf.format(dateTime).toString(); } /** * 得到当前时间 return java.sql.Timestamp * * @return Timestamp */ public static Timestamp getNowTimestamp() { long curTime = System.currentTimeMillis(); return new Timestamp(curTime); } }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值