使用日期工具类:DateUtil
利用java开发,避免不了String、Date转换,前一天、后一天等问题。给出一个工具类,仅供学习交流。
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.Logger; public class DateUtil { public final static long ONE_DAY_SECONDS = 86400;
public final static String shortFormat = "yyyyMMdd";
public final static String longFormat = "yyyyMMddHHmmss";
public final static String concurrentFormat = "yyyyMMddHHmmssSSS";
public final static String shortConcurrentFormat = "yyMMddHHmmssSSS";
public final static String webFormat = "yyyy-MM-dd";
public final static String webMonthFormat = "yyyy-MM";
public final static String timeFormat = "HH:mm:ss";
public final static String monthFormat = "yyyyMM";
public final static String chineseDtFormat = "yyyy年MM月dd日";
public final static String chineseYMFormat = "yyyy年MM月";
public final static String newFormat = "yyyy-MM-dd HH:mm:ss";
public final static String noSecondFormat = "yyyy-MM-dd HH:mm";
public final static String MdFormat = "MM-dd";
public final static long ONE_DAY_MILL_SECONDS = 86400000; public static DateFormat getNewDateFormat(String pattern) {
DateFormat df = new SimpleDateFormat(pattern); df.setLenient(false);
return df;
} public static String format(Date date, String format) {
if (date == null) {
return null;
} return new SimpleDateFormat(format).format(date);
} public static String format(String dateStr, String oldFormat, String newFormat) {
if (dateStr == null) {
return null;
} String result = null;
DateFormat oldDateFormat = new SimpleDateFormat(oldFormat);
DateFormat newDateFormat = new SimpleDateFormat(newFormat); try {
Date date = oldDateFormat.parse(dateStr);
result = newDateFormat.format(date);
} catch (ParseException e) {
e.printStackTrace();
} return result;
} public static Date parseDateNoTime(String sDate) {
DateFormat dateFormat = new SimpleDateFormat(shortFormat); Date date = null;
if ((sDate == null) || (sDate.length() < shortFormat.length())) {
return null;
} if (!StringUtil.isNumeric(sDate)) {
return null;
} try {
date = dateFormat.parse(sDate);
} catch (ParseException e) {
e.printStackTrace();
} return date;
} public static Date parseDateNoTime(String sDate, String format) throws ParseException {
if (StringUtil.isBlank(format)) {
throw new ParseException("Null format. ", 0);
} DateFormat dateFormat = new SimpleDateFormat(format); if ((sDate == null) || (sDate.length() < format.length())) {
throw new ParseException("length too little", 0);
} return dateFormat.parse(sDate);
} public static Date parseDateNoTimeWithDelimit(String sDate, String delimit)
throws ParseException {
sDate = sDate.replaceAll(delimit, ""); DateFormat dateFormat = new SimpleDateFormat(shortFormat); if ((sDate == null) || (sDate.length() != shortFormat.length())) {
throw new ParseException("length not match", 0);
} return dateFormat.parse(sDate);
} public static Date parseDateLongFormat(String sDate) {
DateFormat dateFormat = new SimpleDateFormat(longFormat);
Date d = null; if ((sDate != null) && (sDate.length() == longFormat.length())) {
try {
d = dateFormat.parse(sDate);
} catch (ParseException ex) {
return null;
}
} return d;
} public static Date parseDateNewFormat(String sDate) {
DateFormat dateFormat = new SimpleDateFormat(newFormat);
Date d = null;
dateFormat.setLenient(false);
if ((sDate != null) && (sDate.length() == newFormat.length())) {
try {
d = dateFormat.parse(sDate);
} catch (ParseException ex) {
return null;
}
}
return d;
} public static Date parseDateNoSecondFormat(String sDate) {
DateFormat dateFormat = new SimpleDateFormat(noSecondFormat);
Date d = null;
dateFormat.setLenient(false);
if ((sDate != null) && (sDate.length() == noSecondFormat.length())) {
try {
d = dateFormat.parse(sDate);
} catch (ParseException ex) {
return null;
}
}
return d;
} public static Date parseDateWebFormat(String sDate) {
DateFormat dateFormat = new SimpleDateFormat(webFormat);
Date d = null;
dateFormat.setLenient(false);
if ((sDate != null) && (sDate.length() == webFormat.length())) {
try {
d = dateFormat.parse(sDate);
} catch (ParseException ex) {
return null;
}
}
return d;
} public static Date parseDateWebMonthFormat(String sDate) {
DateFormat dateFormat = new SimpleDateFormat(webMonthFormat);
Date d = null;
dateFormat.setLenient(false);
if ((sDate != null) && (sDate.length() == webMonthFormat.length())) {
try {
d = dateFormat.parse(sDate);
} catch (ParseException ex) {
return null;
}
}
return d;
} /**
* 计算当前时间几小时之后的时间
*
* @param date
* @param hours
*
* @return
*/
public static Date addHours(Date date, long hours) {
return addMinutes(date, hours * 60);
} /**
* 计算当前时间几分钟之后的时间
*
* @param date
* @param minutes
*
* @return
*/
public static Date addMinutes(Date date, long minutes) {
return addSeconds(date, minutes * 60);
} /**
* @param date1
* @param secs
*
* @return
*/ public static Date addSeconds(Date date1, long secs) {
return new Date(date1.getTime() + (secs * 1000));
} /**
* 判断输入的字符串是否为合法的小时
*
* @param hourStr
*
* @return true/false
*/
public static boolean isValidHour(String hourStr) {
if (!StringUtil.isEmpty(hourStr) && StringUtil.isNumeric(hourStr)) {
int hour = new Integer(hourStr).intValue(); if ((hour >= 0) && (hour <= 23)) {
return true;
}
} return false;
} /**
* 判断输入的字符串是否为合法的分或秒
*
* @param minuteStr
*
* @return true/false
*/
public static boolean isValidMinuteOrSecond(String str) {
if (!StringUtil.isEmpty(str) && StringUtil.isNumeric(str)) {
int hour = new Integer(str).intValue(); if ((hour >= 0) && (hour <= 59)) {
return true;
}
} return false;
} /**
* 取得新的日期
*
* @param date1
* 日期
* @param days
* 天数
*
* @return 新的日期
*/
public static Date addDays(Date date1, long days) {
Calendar cal = Calendar.getInstance();
cal.setTime(date1);
cal.add(Calendar.DATE, (int) days);
return cal.getTime();
} public static String getTomorrowDateString(String sDate) throws ParseException {
Date aDate = parseDateNoTime(sDate); aDate = addSeconds(aDate, ONE_DAY_SECONDS); return getDateString(aDate);
} public static String getTomorrowDateNewFMTString(String sDate) throws ParseException {
Date aDate = parseDateWebFormat(sDate);
aDate = addDays(aDate, 1);
return getWebDateString(aDate);
} public static String getTomorrowDateNewFormatString(String sDate) throws ParseException {
Date aDate = parseDateNewFormat(sDate);
aDate = addDays(aDate, 1);
return getWebDateString(aDate);
} public static String getLongDateString(Date date) {
DateFormat dateFormat = new SimpleDateFormat(longFormat); return getDateString(date, dateFormat);
} public static String getNewFormatDateString(Date date) {
DateFormat dateFormat = new SimpleDateFormat(newFormat);
return getDateString(date, dateFormat);
} public static String getWebFormatDateString(Date date) {
DateFormat dateFormat = new SimpleDateFormat(webFormat);
return getDateString(date, dateFormat);
} public static String getConcurrentFormatDateString(Date date) {
DateFormat dateFormat = new SimpleDateFormat(concurrentFormat);
return getDateString(date, dateFormat);
} public static String getDateString(Date date, DateFormat dateFormat) {
if (date == null || dateFormat == null) {
return null;
} return dateFormat.format(date);
} public static String getYesterDayDateString(String sDate) throws ParseException {
Date aDate = parseDateNoTime(sDate); aDate = addSeconds(aDate, -ONE_DAY_SECONDS); return getDateString(aDate);
} /**
* @return 当天的时间格式化为"yyyyMMdd"
*/
public static String getDateString(Date date) {
DateFormat df = getNewDateFormat(shortFormat); return df.format(date);
} public static String getWebDateString(Date date) {
DateFormat dateFormat = getNewDateFormat(webFormat); return getDateString(date, dateFormat);
} /**
* 取得“X年X月X日”的日期格式
*
* @param date
*
* @return
*/
public static String getChineseDateString(Date date) {
DateFormat dateFormat = getNewDateFormat(chineseDtFormat); return getDateString(date, dateFormat);
} public static String getTodayString() {
DateFormat dateFormat = getNewDateFormat(shortFormat); return getDateString(new Date(), dateFormat);
} public static String getTomorrowString() {
DateFormat dateFormat = getNewDateFormat(shortFormat); return getDateString(DateUtil.addDays(new Date(), 1), dateFormat);
} public static String getTimeString(Date date) {
DateFormat dateFormat = getNewDateFormat(timeFormat); return getDateString(date, dateFormat);
} public static String getBeforeDayString(int days) {
Date date = new Date(System.currentTimeMillis() - (ONE_DAY_MILL_SECONDS * days));
DateFormat dateFormat = getNewDateFormat(shortFormat); return getDateString(date, dateFormat);
} /**
* 取得两个日期间隔毫秒数(日期1-日期2)
*
* @param one
* 日期1
* @param two
* 日期2
*
* @return 间隔秒数
*/
public static long getDiffMillis(Date one, Date two) {
Calendar sysDate = new GregorianCalendar(); sysDate.setTime(one); Calendar failDate = new GregorianCalendar(); failDate.setTime(two);
return (sysDate.getTimeInMillis() - failDate.getTimeInMillis());
} /**
* 取得两个日期间隔秒数(日期1-日期2)
*
* @param one
* 日期1
* @param two
* 日期2
*
* @return 间隔秒数
*/
public static long getDiffSeconds(Date one, Date two) {
Calendar sysDate = new GregorianCalendar(); sysDate.setTime(one); Calendar failDate = new GregorianCalendar(); failDate.setTime(two);
return (sysDate.getTimeInMillis() - failDate.getTimeInMillis()) / 1000;
} /**
* 取得两个日期间隔分钟数(日期1-日期2)
*
* @param one
* 日期1
* @param two
* 日期2
*
* @return 间隔秒数
*/
public static long getDiffMinutes(Date one, Date two) {
Calendar sysDate = new GregorianCalendar(); sysDate.setTime(one); Calendar failDate = new GregorianCalendar(); failDate.setTime(two);
return (sysDate.getTimeInMillis() - failDate.getTimeInMillis()) / (60 * 1000);
} /**
* 取得两个日期的间隔天数
*
* @param one
* @param two
*
* @return 间隔天数
*/
public static long getDiffDays(Date one, Date two) {
Calendar sysDate = new GregorianCalendar(); sysDate.setTime(one); Calendar failDate = new GregorianCalendar(); failDate.setTime(two);
return (sysDate.getTimeInMillis() - failDate.getTimeInMillis()) / (24 * 60 * 60 * 1000);
} /**
* 取得两个日期相差的自然日
*
* @param date1
* @param date2
* @return
*/
public static long getDiffNaturalDays(Date date1, Date date2) { Long diffDays = 0L; DateFormat dateFormat = new SimpleDateFormat(webFormat); //去掉时分秒
String dateStr1 = dateFormat.format(date1);
String dateStr2 = dateFormat.format(date2); try {
diffDays = (dateFormat.parse(dateStr1).getTime() - dateFormat.parse(dateStr2).getTime()) / (24 * 60 * 60 * 1000);
} catch (ParseException e) {
e.printStackTrace();
} return Math.abs(diffDays);
} /**
* 取得两个日期相差的自然日
*
* @param date1
* @param date2
* @return
*/
public static long getDiffNaturalDayNotAbs(Date date1, Date date2) { Long diffDays = 0L; DateFormat dateFormat = new SimpleDateFormat(webFormat); //去掉时分秒
String dateStr1 = dateFormat.format(date1);
String dateStr2 = dateFormat.format(date2); try {
diffDays = (dateFormat.parse(dateStr1).getTime() - dateFormat.parse(dateStr2).getTime()) / (24 * 60 * 60 * 1000);
} catch (ParseException e) {
e.printStackTrace();
} return diffDays;
} public static String getBeforeDayString(String dateString, int days) {
Date date;
DateFormat df = getNewDateFormat(shortFormat); try {
date = df.parse(dateString);
} catch (ParseException e) {
date = new Date();
} date = new Date(date.getTime() - (ONE_DAY_MILL_SECONDS * days)); return df.format(date);
} public static boolean isValidShortDateFormat(String strDate) {
if (strDate.length() != shortFormat.length()) {
return false;
} try {
Integer.parseInt(strDate); // ---- 避免日期中输入非数字 ----
} catch (Exception NumberFormatException) {
return false;
} DateFormat df = getNewDateFormat(shortFormat); try {
df.parse(strDate);
} catch (ParseException e) {
return false;
} return true;
} public static boolean isValidShortDateFormat(String strDate, String delimiter) {
String temp = strDate.replaceAll(delimiter, ""); return isValidShortDateFormat(temp);
} /**
* 判断表示时间的字符是否为符合yyyyMMddHHmmss格式
*
* @param strDate
* @return
*/
public static boolean isValidLongDateFormat(String strDate) {
if (strDate.length() != longFormat.length()) {
return false;
} try {
Long.parseLong(strDate); // ---- 避免日期中输入非数字 ----
} catch (Exception NumberFormatException) {
return false;
} DateFormat df = getNewDateFormat(longFormat); try {
df.parse(strDate);
} catch (ParseException e) {
return false;
} return true;
} /**
* 判断表示时间的字符是否为符合yyyyMMddHHmmss格式
*
* @param strDate
* @param delimiter
* @return
*/
public static boolean isValidLongDateFormat(String strDate, String delimiter) {
String temp = strDate.replaceAll(delimiter, ""); return isValidLongDateFormat(temp);
} public static String getShortDateString(String strDate) {
return getShortDateString(strDate, "-|/");
} public static String getShortDateString(String strDate, String delimiter) {
if (StringUtil.isBlank(strDate)) {
return null;
} String temp = strDate.replaceAll(delimiter, ""); if (isValidShortDateFormat(temp)) {
return temp;
} return null;
} public static String getShortFirstDayOfMonth() {
Calendar cal = Calendar.getInstance();
Date dt = new Date(); cal.setTime(dt);
cal.set(Calendar.DAY_OF_MONTH, 1); DateFormat df = getNewDateFormat(shortFormat); return df.format(cal.getTime());
} public static String getWebTodayString() {
DateFormat df = getNewDateFormat(webFormat); return df.format(new Date());
} /**
* 获取当月首日
*
* @return
*/
public static String getWebFirstDayOfMonth() {
Calendar cal = Calendar.getInstance();
Date dt = new Date(); cal.setTime(dt);
cal.set(Calendar.DAY_OF_MONTH, 1); DateFormat df = getNewDateFormat(webFormat); return df.format(cal.getTime());
} /**
* 获取当月的总天数
*
* @return
*/
public static int getDaysOfMonth() {
Calendar cal = Calendar.getInstance(Locale.CHINA);
int days = cal.getActualMaximum(Calendar.DATE);
return days;
} public static String convert(String dateString, DateFormat formatIn, DateFormat formatOut) {
try {
Date date = formatIn.parse(dateString); return formatOut.format(date);
} catch (ParseException e) {
return "";
}
} public static String convert2WebFormat(String dateString) {
DateFormat df1 = getNewDateFormat(shortFormat);
DateFormat df2 = getNewDateFormat(webFormat); return convert(dateString, df1, df2);
} public static String convert2ChineseDtFormat(String dateString) {
DateFormat df1 = getNewDateFormat(shortFormat);
DateFormat df2 = getNewDateFormat(chineseDtFormat); return convert(dateString, df1, df2);
} public static String convertFromWebFormat(String dateString) {
DateFormat df1 = getNewDateFormat(shortFormat);
DateFormat df2 = getNewDateFormat(webFormat); return convert(dateString, df2, df1);
} public static boolean webDateNotLessThan(String date1, String date2) {
DateFormat df = getNewDateFormat(webFormat); return dateNotLessThan(date1, date2, df);
} /**
* @param date1
* @param date2
* @param dateWebFormat2
*
* @return
*/
public static boolean dateNotLessThan(String date1, String date2, DateFormat format) {
try {
Date d1 = format.parse(date1);
Date d2 = format.parse(date2); if (d1.before(d2)) {
return false;
} else {
return true;
}
} catch (ParseException e) {
return false;
}
} public static String getEmailDate(Date today) {
String todayStr;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日HH:mm:ss"); todayStr = sdf.format(today);
return todayStr;
} public static String getSmsDate(Date today) {
String todayStr;
SimpleDateFormat sdf = new SimpleDateFormat("MM月dd日HH:mm"); todayStr = sdf.format(today);
return todayStr;
} public static String formatMonth(Date date) {
if (date == null) {
return null;
} return new SimpleDateFormat(monthFormat).format(date);
} /**
* 获取系统日期的前一天日期,返回Date
*
* @return
*/
public static Date getBeforeDate() {
Date date = new Date(); return new Date(date.getTime() - (ONE_DAY_MILL_SECONDS));
} /**
* 获得指定时间当天起点时间
*
* @param date
* @return
*/
public static Date getDayBegin(Date date) {
DateFormat df = new SimpleDateFormat("yyyyMMdd");
df.setLenient(false); String dateString = df.format(date); try {
return df.parse(dateString);
} catch (ParseException e) {
return date;
}
} /**
* 根据Date对象返回今天是星期几
*
* @param date
* @return 1:星期日 2:星期一 3:星期二 4:星期三 5:星期四 6:星期五 7:星期六
*/
public static int getWeekDayFromDateEntity(Date date) { Calendar calendar = Calendar.getInstance();// 获得一个日历
calendar.setTime(date);
int number = calendar.get(Calendar.DAY_OF_WEEK);// 星期表示1-7,是从星期日开始, return number; } /**
* 判断参date上min分钟后,是否小于当前时间
*
* @param date
* @param min
* @return
*/
public static boolean dateLessThanNowAddMin(Date date, long min) {
return addMinutes(date, min).before(new Date()); } public static boolean isBeforeNow(Date date) {
if (date == null)
return false;
return date.compareTo(new Date()) < 0;
} private static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); // 获得当前月--开始日期
public static Date getMinMonthDate(String date) {
Calendar calendar = Calendar.getInstance();
try {
calendar.setTime(dateFormat.parse(date));
calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
return calendar.getTime();
} catch (ParseException e) {
return null;
}
} // 获得当前月--结束日期
public static Date getMaxMonthDate(String date) {
Calendar calendar = Calendar.getInstance();
try {
calendar.setTime(dateFormat.parse(date));
calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
return calendar.getTime();
} catch (ParseException e) {
return null;
}
} public static Date parseNoSecondFormat(String sDate) throws ParseException {
DateFormat dateFormat = new SimpleDateFormat(noSecondFormat); if ((sDate == null) || (sDate.length() < noSecondFormat.length())) {
throw new ParseException("length too little", 0);
} if (!StringUtil.isNumeric(sDate)) {
throw new ParseException("not all digit", 0);
} return dateFormat.parse(sDate);
} /*
*
* date日期转变成 制定格式字符串
*
*/
public static String convertDate2String(Date date, String time_pattern) { SimpleDateFormat sf = new SimpleDateFormat(time_pattern); return sf.format(date); } /**
* 根据Date对象返回天
*
*
* @param date
*/
public static int getDayFromDateEntity(Date date) {
Calendar calendar = Calendar.getInstance();// 获得一个日历
calendar.setTime(date);
int number = calendar.get(Calendar.DATE);// 星期表示1-7,是从星期日开始,
return number; } public static int compare_date(String DATE1, String DATE2) {
DateFormat df = new SimpleDateFormat("yyyy-MM");
try {
Date dt1 = df.parse(DATE1);
Date dt2 = df.parse(DATE2);
if (dt1.getTime() > dt2.getTime()) {
//System.out.println("dt1 在dt2前");
return 1;
} else if (dt1.getTime() < dt2.getTime()) {
//System.out.println("dt1在dt2后");
return -1;
} else {
return 0;
}
} catch (Exception exception) {
exception.printStackTrace();
}
return 0;
} public static String getCurMonth() {
return format(new Date(), webMonthFormat);
} public static String getChineseYMString(String date) { SimpleDateFormat sdf = new SimpleDateFormat(chineseYMFormat);
try {
Date datea = sdf.parse(date);
DateFormat dateFormat = getNewDateFormat(chineseYMFormat);
return getDateString(datea, dateFormat);
} catch (ParseException ex) {
Logger.getLogger(DateUtil.class.getName()).log(Level.SEVERE, null, ex);
return date;
} } public static Date getPreMonthDate(String date) {
SimpleDateFormat sdf = new SimpleDateFormat(webMonthFormat);
try {
Date datea = sdf.parse(date);
Calendar cal = Calendar.getInstance();
cal.setTime(datea);
cal.add(Calendar.MONTH, -1);
return cal.getTime();
} catch (ParseException ex) {
Logger.getLogger(DateUtil.class.getName()).log(Level.SEVERE, null, ex);
return new Date();
} } public static Date getNextMonthDate(String date) {
SimpleDateFormat sdf = new SimpleDateFormat(webMonthFormat);
try {
Date datea = sdf.parse(date);
Calendar cal = Calendar.getInstance();
cal.setTime(datea);
cal.add(Calendar.MONTH, 1);
return cal.getTime();
} catch (ParseException ex) {
Logger.getLogger(DateUtil.class.getName()).log(Level.SEVERE, null, ex);
return new Date();
}
} /**
* 获取指定日期的当月的第一天
*
* @param date
* @return
*/
public static String getAssignedDateFirstDayOfMonth(Date date) {
Calendar cal = Calendar.getInstance(); cal.setTime(date);
cal.set(Calendar.DAY_OF_MONTH, cal.getActualMinimum(Calendar.DAY_OF_MONTH)); DateFormat df = getNewDateFormat(webFormat); return df.format(cal.getTime());
} /**
* 获取指定日期的当月的最后一天
*
* @param date
* @return
*/
public static String getAssignedDateLastDayOfMonth(Date date) {
Calendar cal = Calendar.getInstance(); cal.setTime(date);
cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH)); DateFormat df = getNewDateFormat(webFormat); return df.format(cal.getTime());
}
public static Date getNextDate(Date date) {
try {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.DAY_OF_MONTH, 1);
Date date1 = new Date(calendar.getTimeInMillis());
return date1;
} catch (Exception ex) {
Logger.getLogger(DateUtil.class.getName()).log(Level.SEVERE, null, ex);
return date;
}
} /**
* 根据年 月 获取对应的月份 天数
* */
public static int getDaysByYearMonth(int year, int month) {
Calendar a = Calendar.getInstance();
a.set(Calendar.YEAR, year);
a.set(Calendar.MONTH, month - 1);
a.set(Calendar.DATE, 1);
a.roll(Calendar.DATE, -1);
int maxDate = a.get(Calendar.DATE);
return maxDate;
} }
使用日期工具类:DateUtil的更多相关文章
- 日期工具类 - DateUtil.java
日期工具类,提供对日期的格式化和转换方法.获取区间日期.指定日期.每月最后一天等. 源码如下:(点击下载 -DateUtil.java.commons-lang-2.6.jar ) import ja ...
- java日期工具类DateUtil
一名优秀的程序员,不仅需要有着丰富解决问题的方案,还需要的便是代码的沉淀,这不仅有助于自己快速的开发程序,也有利于保证程序的健壮.那如何才能沉淀自己的”代码“呢?从自己编写util开始其实就是一个不错 ...
- 【uniapp 开发】日期工具类 -- DateUtil
日期格式转毫秒值 var time = '2019-08-08 12:09:34'; var time222 = time.replace("-", "/"). ...
- java日期工具类DateUtil-续一
上篇文章中,我为大家分享了下DateUtil第一版源码,但就如同文章中所说,我发现了还存在不完善的地方,所以我又做了优化和扩展. 更新日志: 1.修正当字符串日期风格为MM-dd或yyyy-MM时,若 ...
- JAVA 日期格式工具类DateUtil.java
DateUtil.java package pers.kangxu.datautils.utils; import java.text.SimpleDateFormat; import java.ut ...
- JS 日期工具类-基于yDate
源码下载 前言:最近在用到JS日期操作时,发现有一些不方便,于是搜素了一些网上的资料,基于一个开源工具类-yDate 进行了个性化定制,封装成了一个日期工具类工具函数大概介绍:1.普通的日期操作2. ...
- java日期工具类DateUtil-续二
该版本是一次较大的升级,农历相比公历复杂太多(真佩服古人的智慧),虽然有规律,但涉及到的取舍.近似的感念太多,况且本身的概念就已经很多了,我在网上也是查阅了很多的资料,虽然找到一些计算的方法,但都有些 ...
- JAVA 日期工具类的总结
一般,在项目中,我们会会经常使用到日期的各种方式的处理,在各个业务逻辑操作中,都需要相关的日期操作,因此,实现项目中的日期工具类的提出,还是十分重要的,下面,就项目中常用到的日期的相关操作方式,做了一 ...
- Java案例——日期工具类
需求:定义一个日期工具类,包含两个方法,按日期转化成指定格式的字符串,把字符串解析为指定格式的日期 然后定义一个测试类测试 分析: 1.定义一个日期工具类 2.定义一个方法dateToString,用 ...
- Java日期工具类,Java时间工具类,Java时间格式化
Java日期工具类,Java时间工具类,Java时间格式化 >>>>>>>>>>>>>>>>>&g ...
随机推荐
- Android扫描二维码 实现 登录网页
工程代码:ScanQRcode.zip ------------------------------------------------------------------ 1. 扫描二维码登录的实现 ...
- 项目知识点.Part2
1. 取消collectionView头视图重叠情况:以下两种情况效果一样 但是有一点点bug 每次remove之后 需要把视图刷到上面才会显示(后续会改进方法) for (UIView *view ...
- ios CAF音频转换为MP3
Url:http://blog.csdn.net/ysy441088327/article/details/7392842#reply 为了达到 iPhone 与 Android 实现音频互通. 那么 ...
- AST抽象语法树
抽象语法树简介 (一)简介 抽象语法树(abstract syntax code,AST)是源代码的抽象语法结构的树状表示,树上的每个节点都表示源代码中的一种结构,这所以说是抽象的,是因为抽象语法树并 ...
- [BZOJ 3626] [LNOI2014] LCA 【树链剖分 + 离线 + 差分询问】
题目链接: BZOJ - 3626 题目分析 考虑这样的等价问题,如果我们把一个点 x 到 Root 的路径上每个点的权值赋为 1 ,其余点的权值为 0,那么从 LCA(x, y) 的 Depth 就 ...
- Mysql中类似于nvl()函数的ifnull()函数
IFNULL(expr1,expr2) 如果expr1不是NULL,IFNULL()返回expr1,否则它返回expr2.IFNULL()返回一个数字或字符串值,取决于它被使用的上下文环境. mysq ...
- svn图形客户端:smartsvn,svnmanager,rapidsvn,svnworkbench,rabbitsvn,Esvn, trac
svn图形客户端: smartsvn,http://www.oschina.net/p/smartsvn, 不用安装直接运行 qsvn, http://www.oschina.net/p/qsvn r ...
- bzoj3438
很容易想到是最小割模型首先对于一个点i,从s到i连一条容量为ai的边,再从i连一条容量为bi的边到t然后就是处理附加权的问题了一开始受到之前的思维定势的影响,一直在思考怎么在作物之间连边由于每种额外收 ...
- bzoj1036
树链剖分的基本题详细介绍在http://blog.sina.com.cn/s/blog_7a1746820100wp67.html通过树链剖分我们就可以在树上做线段树操作,完成解答 ; type no ...
- CH Round #51 - Shinrein祭 #1
A.Phorni 题目:http://www.contesthunter.org/contest/CH%20Round%20%2351%20-%20Shinrein祭%20%231/Phorni 没做 ...