- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章Java日期处理工具类DateUtils详解由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
本文实例为大家分享了Java日期处理工具类DateUtils的具体代码,供大家参考,具体内容如下 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
|
import
java.sql.Timestamp;
import
java.text.ParseException;
import
java.text.SimpleDateFormat;
import
java.util.Calendar;
import
java.util.Date;
/**
* <日期时间处理工具类>
*/
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();
// 日期型字符串格式错误
}
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());
}
/**
* <生成最小的当天日期值>
* @return 最小的当天日期值
*/
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() {
}
}
|
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我.
原文链接:http://blog.csdn.net/tang9140/article/details/38760013 。
最后此篇关于Java日期处理工具类DateUtils详解的文章就讲到这里了,如果你想了解更多关于Java日期处理工具类DateUtils详解的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
我的数据库中有两张表,一张用于 field ,另一张用于预订。我需要的是一个查询来选择所有未预订的 field 。见下文: 餐 table 预订具有以下字段: bk_id venue_id 作为(预订
嗨,我是编码新手,我有一些培训项目,其中包括从 HTML 表单输入 MySQL 数据库。它就像你玩过的游戏的日志。第一个日期输入是您开始游戏的时间,第二个日期输入是您完成游戏的时间。但我需要检查器或类
我是这个 sql 编码的新手,我正在尝试学习新的东西。因此,我创建了一个交货表,其中包含一些属性,如商品代码、交货日期、交货数量。所以如何从同一张表中获取第一个交货日期(最小日期)和交货数量以及最晚交
我从支付网关返回了这个日期 2014-05-15T08:40:52+01:00 我得到 2014-05-15T08:40:52 但我无法识别时区 +01:00 的含义 我的位置时区是 UTC−06:0
我快要疯了,请帮忙。 我有一列包含日期时间值。 我需要找到每天的最小值和最大值。 数据看起来像这样 2012-11-23 05:49:26.000 2012-11-23 07:55:43.000
我从 json 数据中获取日期为 2015 年 4 月 15 日晚上 10:15我只想在 html 页面中显示 json 响应数据的时间,例如 10:15 PM这里我放了我的js函数和html代码 J
是否有 javascript 库或其他机制允许我将 .NET 日期/时间格式字符串(即 yyyy-MM-dd HH:mm:ss)传递给 javascript函数并让它相应地解析提供的日期时间值?我一直
我正在使用以下代码以正确的格式获取当前的 UTC 时间,但客户返回并要求时间戳现在使用 EST 而不是 UTC。我搜索了 Google 和 stackoverflow,但找不到适用于我现有代码的答案。
我有以下日期的平均温度数据。我想找到连续至少 5 天低于或高于 0 摄氏度的开始日期。 date_short mean.temp 1 2018-05-18 17.54 2 2018-05-19
它可以在其他网络浏览器中使用,但 IE11 返回无效日期。 为了调试我使用了下面的代码。 console.log('before - ' + date.value); date.value = new
我在 Excel 中有一个数据的 Web 提取,其中日期列带有/Date(1388624400000)/。我需要在 Excel 中将其转换为日期。 最佳答案 能够从 here 中推断出它. 假设字符串
嗨,我的 Schmema 有一个带有 ISO 日期的字段: ISODate("2015-04-30T14:47:46.501Z") Paypal 在成功付款后以该形式返回日期对象: Time/Date
我的 table : CREATE TABLE `tbdata` ( `ID` INT(10) NOT NULL AUTO_INCREMENT, `PatientID` INT(10) NOT
我正在 Ubuntu 服务器 12.04 中编写一个 shell 脚本,它应该比较日志文件中的一些数据。在日志文件中,日期以以下格式给出: [Mon Apr 08 15:02:54 2013] 如您所
我想使用 GROUP BY WITH ROLLUP 创建一个表并获取总行数而不是 null。 $sql ="SELECT IF(YEAR(transaktioner.datum
我正在创建博客文章,在成功迁移我的博客文件后,当我转到我网站的博客页面时返回一个错误(无法解析其余部分:':“Ymd”'来自'post.date|date: "Ymd"') 我似乎无法确定这是语法错误
我正在尝试获取要插入到 CAML 查询中的月份范围,即:2010-09-01 和 2010-09-30。 我使用以下代码生成这两个值: var month = "10/2010"; var month
如何将代码document.write("直到指定日期")更改为writeMessage(date)中的日期?此外,writeMessage(date) 中的日期未正确显示(仅显示年份)。感谢您帮助解
我在 Windows (XP) 和 Linux 上都尝试过 utime()。在 Windows 上我得到一个 EACCES 错误,在 Linux 上我没有得到任何错误(但时间没有改变)。我的 utim
我正在尝试计算发生在同一日期的值的总和(在 XYZmin 中)。 我的数据看起来像这样, bar <- structure(list(date = structure(c(15622, 15622,
我是一名优秀的程序员,十分优秀!