欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

Java如何實(shí)現(xiàn)日期處理工具類DateUtils

小編給大家分享一下Java如何實(shí)現(xiàn)日期處理工具類DateUtils,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!

成都創(chuàng)新互聯(lián)主要從事成都做網(wǎng)站、網(wǎng)站建設(shè)、網(wǎng)頁(yè)設(shè)計(jì)、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)撫寧,十年網(wǎng)站建設(shè)經(jīng)驗(yàn),價(jià)格優(yōu)惠、服務(wù)專業(yè),歡迎來電咨詢建站服務(wù):13518219792

具體內(nèi)容如下

import java.sql.Timestamp; 
import java.text.ParseException; 
import java.text.SimpleDateFormat; 
import java.util.Calendar; 
import java.util.Date; 
 
/** 
 * <日期時(shí)間處理工具類> 
 */ 
public class DateUtils { 
  
 /** 
  * Date format pattern this is often used. 
  */ 
 public static final String PATTERN_YMD = "yyyy-MM-dd"; 
  
 /** 
  * Date format pattern this is often used. 
  */ 
 public static final String PATTERN_YMDHMS="yyyy-MM-dd HH:mm:ss"; 
  
 /** 
  * Formats the given date according to the YMD pattern. 
  * 
  * @param date The date to format. 
  * @return An YMD formatted date string. 
  * 
  * @see #PATTERN_YMD 
  */ 
 public static String formatDate(Date date) { 
  return formatDate(date, PATTERN_YMD); 
 } 
  
 /** 
  * Formats the given date according to the specified pattern. The pattern 
  * must conform to that used by the {@link SimpleDateFormat simple date 
  * format} class. 
  * 
  * @param date The date to format. 
  * @param pattern The pattern to use for formatting the date. 
  * @return A formatted date string. 
  * 
  * @throws IllegalArgumentException If the given date pattern is invalid. 
  * 
  * @see SimpleDateFormat 
  */ 
 public static String formatDate(Date date, String pattern) { 
  if (date == null) 
   throw new IllegalArgumentException("date is null"); 
  if (pattern == null) 
   throw new IllegalArgumentException("pattern is null"); 
   
  SimpleDateFormat formatter = new SimpleDateFormat(pattern); 
  return formatter.format(date); 
 } 
  
 /** 
  * Parses a date value. The format used for parsing the date value are retrieved from 
  * the default PATTERN_YMD. 
  * 
  * @param dateValue the date value to parse 
  * 
  * @return the parsed date 
  * 
  * @throws IllegalArgumentException If the given dateValue is invalid. 
  */ 
 public static Date parseDate(String dateValue) { 
  return parseDate(dateValue, null); 
 } 
  
 /** 
  * Parses the date value using the given date format. 
  * 
  * @param dateValue the date value to parse 
  * @param dateFormat the date format to use 
  * 
  * @return the parsed date. if parse is failed , return null 
  * 
  * @throws IllegalArgumentException If the given dateValue is invalid. 
  */ 
 public static Date parseDate(String dateValue, String dateFormat) { 
  if (dateValue == null) { 
   throw new IllegalArgumentException("dateValue is null"); 
  } 
  if (dateFormat == null) { 
   dateFormat = PATTERN_YMD; 
  } 
   
  SimpleDateFormat df = new SimpleDateFormat(dateFormat); 
  Date result = null; 
  try { 
   result = df.parse(dateValue); 
  } 
  catch (ParseException pe) { 
   pe.printStackTrace();// 日期型字符串格式錯(cuò)誤 
  } 
  return result; 
 } 
  
 /** 
  * Adds a number of years to a date returning a new object. 
  * The original date object is unchanged. 
  * 
  * @param date the date, not null 
  * @param amount the amount to add, may be negative 
  * @return the new date object with the amount added 
  * @throws IllegalArgumentException if the date is null 
  */ 
 public static Date addYears(Date date, int amount) { 
  return add(date, Calendar.YEAR, amount); 
 } 
  
 /** 
  * Adds a number of years to a timestamp returning a new object. 
  * The original timestamp object is unchanged. 
  * 
  * @param timestamp the timestamp, not null 
  * @param amount the amount to add, may be negative 
  * @return the new timestamp object with the amount added 
  * @throws IllegalArgumentException if the timestamp is null 
  */ 
 public static Timestamp addYears(Timestamp timestamp, int amount) { 
  return add(timestamp, Calendar.YEAR, amount); 
 } 
  
 //----------------------------------------------------------------------- 
 /** 
  * Adds a number of months to a date returning a new object. 
  * The original date object is unchanged. 
  * 
  * @param date the date, not null 
  * @param amount the amount to add, may be negative 
  * @return the new date object with the amount added 
  * @throws IllegalArgumentException if the date is null 
  */ 
 public static Date addMonths(Date date, int amount) { 
  return add(date, Calendar.MONTH, amount); 
 } 
  
 /** 
  * Adds a number of months to a timestamp returning a new object. 
  * The original timestamp object is unchanged. 
  * 
  * @param timestamp the timestamp, not null 
  * @param amount the amount to add, may be negative 
  * @return the new timestamp object with the amount added 
  * @throws IllegalArgumentException if the timestamp is null 
  */ 
 public static Timestamp addMonths(Timestamp timestamp, int amount) { 
  return add(timestamp, Calendar.MONTH, amount); 
 } 
  
 //----------------------------------------------------------------------- 
 /** 
  * Adds a number of days to a date returning a new object. 
  * The original date object is unchanged. 
  * 
  * @param date the date, not null 
  * @param amount the amount to add, may be negative 
  * @return the new date object with the amount added 
  * @throws IllegalArgumentException if the date is null 
  */ 
 public static Date addDays(Date date, int amount) { 
  return add(date, Calendar.DATE, amount); 
 } 
  
 /** 
  * Adds a number of days to a timestamp returning a new object. 
  * The original timestamp object is unchanged. 
  * 
  * @param timestamp the timestamp, not null 
  * @param amount the amount to add, may be negative 
  * @return the new timestamp object with the amount added 
  * @throws IllegalArgumentException if the timestamp is null 
  */ 
 public static Timestamp addDays(Timestamp timestamp, int amount) { 
  return add(timestamp, Calendar.DATE, amount); 
 } 
  
 //----------------------------------------------------------------------- 
 /** 
  * Adds a number of minutes to a timestamp returning a new object. 
  * The original timestamp object is unchanged. 
  * 
  * @param timestamp the timestamp, not null 
  * @param amount the amount to add, may be negative 
  * @return the new timestamp object with the amount added 
  * @throws IllegalArgumentException if the timestamp is null 
  */ 
 public static Timestamp addMinutes(Timestamp timestamp, int amount) { 
  return add(timestamp, Calendar.MINUTE, amount); 
 } 
  
 /** 
  * Adds a number of days to current time returning a new object. 
  * 
  * @param amount the amount to add, may be negative 
  * @return the new timestamp object with the amount added 
  */ 
 public static Timestamp addDays(int amount) { 
  Calendar c = Calendar.getInstance(); 
  c.add(Calendar.DATE, amount); 
  return new Timestamp(c.getTimeInMillis()); 
 } 
  
 //----------------------------------------------------------------------- 
 /** 
  * Adds to a date returning a new object. 
  * The original date object is unchanged. 
  * 
  * @param date the date, not null 
  * @param calendarField the calendar field to add to 
  * @param amount the amount to add, may be negative 
  * @return the new date object with the amount added 
  * @throws IllegalArgumentException if the date is null 
  */ 
 private static Date add(Date date, int calendarField, int amount) { 
  if (date == null) { 
   throw new IllegalArgumentException("The date must not be null"); 
  } 
  Calendar c = Calendar.getInstance(); 
  c.setTime(date); 
  c.add(calendarField, amount); 
  return c.getTime(); 
 } 
  
 /** 
  * Adds to a timestamp returning a new object. 
  * The original timestamp object is unchanged. 
  * 
  * @param timestamp the timestamp, not null 
  * @param calendarField the calendar field to add to 
  * @param amount the amount to add, may be negative 
  * @return the new timestamp object with the amount added 
  * @throws IllegalArgumentException if the timestamp is null 
  */ 
 private static Timestamp add(Timestamp timestamp, int calendarField, int amount) { 
  if (timestamp == null) { 
   throw new IllegalArgumentException("The timestamp must not be null"); 
  } 
  Calendar c = Calendar.getInstance(); 
  c.setTime(timestamp); 
  c.add(calendarField, amount); 
  return new Timestamp(c.getTimeInMillis()); 
 } 
  
 /** 
  * <生成最小的當(dāng)天日期值> 
  * @return 最小的當(dāng)天日期值 
  */ 
 public static Timestamp now() { 
  Calendar c = Calendar.getInstance(); 
  c.set(Calendar.HOUR_OF_DAY, 0); 
  c.set(Calendar.MINUTE, 0); 
  c.set(Calendar.SECOND, 0); 
  c.set(Calendar.MILLISECOND, 0); 
  return new Timestamp(c.getTimeInMillis()); 
 } 
  
  
  
 /** This class should not be instantiated. */ 
 private DateUtils() { 
 } 
}

以上是“Java如何實(shí)現(xiàn)日期處理工具類DateUtils”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!

文章標(biāo)題:Java如何實(shí)現(xiàn)日期處理工具類DateUtils
轉(zhuǎn)載來于:http://www.aaarwkj.com/article16/pcdigg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信公眾號(hào)、域名注冊(cè)、全網(wǎng)營(yíng)銷推廣、App開發(fā)小程序開發(fā)響應(yīng)式網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

h5響應(yīng)式網(wǎng)站建設(shè)
97在线视频观看视频在线| 国产第一页第二页在线| 欧美精品国产亚洲另类| 日韩av有码在线播放| 人妻精品久久一区二区三区| 日本欧美激情在线观看| 国产精品蜜臀av在线一区| 欧美一区二区欧美精品| 国产精品又大又黑又长又粗| 国产欧美激情一区二区| 精品中文人妻中文字幕| 日本一本一道高清不卡视频| 亚洲精品视频久久偷拍| 手机不卡高清播放一区二区| 日本韩国三级理伦久久久| 日韩中文不卡人成在线视频 | 久久视频在线播放视频| 欧美日韩国产一区二区三区在线观看| 久久精品色妇熟妇丰满人妻| 小草少妇视频免费看视频| 欧美精品福利一区二区三区| 国产黄色片子在线观看| 日韩精品一区二区国产| 成人免费视频国产免费| 欧美日韩另类激情免费| 国产三级传媒视频在线观看| 一区不卡在线视频免费国产| 丁香婷婷综合激情五月| av福利一区二区三区| 偷拍偷窥女厕一区二区视频| 亚洲成人高清在线视频| 日韩黄色成人免费片子| 日韩av亚洲一区二区三区| 亚洲第一青青草原在线| 亚洲国产成人欧美日韩另类| 91高清国产在线播放| 久久夜色精品亚洲国产| 午夜福利片免费在线观看| 91在线国产精品视频| 亚洲成人av在线蜜桃| 国内精品人妻久久毛片|