日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

java 日期处理 口诀_java时间处理常用方法工具类

發布時間:2023/12/31 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java 日期处理 口诀_java时间处理常用方法工具类 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

java時間處理常用方法工具類 。

import java.io.PrintStream;

2 import java.sql.Time;

3 import java.sql.Timestamp;

4 import java.text.ParsePosition;

5 import java.text.SimpleDateFormat;

6 import java.util.Date;

7 public class TimeUtil

8 {

9 /*

10 * www.pmjava.com java編程

11 */

12 public TimeUtil()

13 {

14 }

15 public static Date strToDate(String sStr)

16 {

17 if (sStr == null)

18 return null;

19 SimpleDateFormat formatter;

20 if (sStr.length() == 19)

21 formatter = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”);

22 else

23 if (sStr.length() == 10)

24 formatter = new SimpleDateFormat(“yyyy-MM-dd”);

25 else

26 if (sStr.length() == 8)

27 formatter = new SimpleDateFormat(“yyyyMMdd”);

28 else

29 if (sStr.length() == 14)

30 formatter = new SimpleDateFormat(“yyyyMMddHHmmss”);

31 else

32 formatter = new SimpleDateFormat(“yyyyMMddHHmmss”);

33 ParsePosition pos = new ParsePosition(0);

34 return formatter.parse(sStr, pos);

35 }

36 public static Timestamp strToDatetime(String s)

37 {

38 return new Timestamp(strToDate(s).getTime());

39 }

40 public static String datetimeToChinese(Date dtSource)

41 {

42 SimpleDateFormat formatter = new SimpleDateFormat(“yyyy年MM月dd日HH時mm分ss秒”);

43 return formatter.format(dtSource);

44 }

45 public static String dateToStr(Date date)

46 {

47 SimpleDateFormat format = new SimpleDateFormat(“yyyyMMdd”);

48 return format.format(date);

49 }

50 public static String datetimeToStr(Date date)

51 {

52 if (date == null)

53 {

54 return “”;

55 } else

56 {

57 SimpleDateFormat formatter = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”);

58 return formatter.format(date);

59 }

60 }

61 public static String today()

62 {

63 return dateToStr(new Date());

64 }

65 public static String now()

66 {

67 return datetimeToStr(new Date());

68 }

69 public static String calcTime(String time, int diffYear, int diffMonth, int diffDate, int diffHour, int diffMinute, int diffSecond)

70 {

71 Timestamp timestamp = strToDatetime(time);

72 timestamp.setYear(timestamp.getYear() + diffYear);

73 timestamp.setMonth(timestamp.getMonth() + diffMonth);

74 timestamp.setDate(timestamp.getDate() + diffDate);

75 timestamp.setHours(timestamp.getHours() + diffHour);

76 timestamp.setMinutes(timestamp.getMinutes() + diffMinute);

77 timestamp.setSeconds(timestamp.getSeconds() + diffSecond);

78 return datetimeToStr(timestamp);

79 }

80 public static String getCurrentTime()

81 {

82 String s = (new Time(System.currentTimeMillis())).toString();

83 return s;

84 }

85 public static String getCurrentDate()

86 {

87 String s = (new java.sql.Date(System.currentTimeMillis())).toString();

88 return s;

89 }

90 public static String getCurrentNow()

91 {

92 String s = getCurrentDate() + ” ” + getCurrentTime();

93 return s;

94 }

95 public static String dateFromStr(String date)

96 {

97 if (date == null || date.length() < 10)

98 return getCurrentDate();

99 else

100 return date.substring(0, 10);

101 }

102 public static String timeFromStr(String date)

103 {

104 if (date == null || date.length() < 19)

105 return “00:00:00″;

106 else

107 return date.substring(11, 19);

108 }

109 public static void main(String args[])

110 {

111 System.out.println(now());

112 }

113 }

http://www.blogjava.net/rrong-m/archive/2009/06/16/282669.html

總結

以上是生活随笔為你收集整理的java 日期处理 口诀_java时间处理常用方法工具类的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。