Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
佳 邓
Gitlab4j Api
Commits
f2d7d11a
Commit
f2d7d11a
authored
Mar 02, 2014
by
Greg Messner
Browse files
Initial check-in.
parent
bfa71828
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/main/java/com/messners/gitlab/api/ISO8601.java
0 → 100644
View file @
f2d7d11a
package
com.messners.gitlab.api
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.util.Calendar
;
import
java.util.Date
;
import
java.util.TimeZone
;
public
class
ISO8601
{
public
static
final
String
PATTERN
=
"yyyy-MM-dd'T'HH:mm:ssZ"
;
public
static
final
String
OUTPUT_PATTERN
=
"yyyy-MM-dd'T'HH:mm:ss'Z'"
;
public
static
final
String
ALTERNATE_PATTERN
=
"yyyy-MM-dd HH:mm:ss"
;
private
static
final
SimpleDateFormat
iso8601Format
;
private
static
final
SimpleDateFormat
iso8601OutputFormat
;
private
static
final
SimpleDateFormat
iso8601AlternateFormat
;
static
{
iso8601Format
=
new
SimpleDateFormat
(
PATTERN
);
iso8601Format
.
setLenient
(
true
);
iso8601Format
.
setTimeZone
(
TimeZone
.
getTimeZone
(
"GMT"
));
iso8601OutputFormat
=
new
SimpleDateFormat
(
OUTPUT_PATTERN
);
iso8601OutputFormat
.
setLenient
(
true
);
iso8601OutputFormat
.
setTimeZone
(
TimeZone
.
getTimeZone
(
"GMT"
));
iso8601AlternateFormat
=
new
SimpleDateFormat
(
ALTERNATE_PATTERN
);
iso8601AlternateFormat
.
setLenient
(
true
);
iso8601AlternateFormat
.
setTimeZone
(
TimeZone
.
getTimeZone
(
"GMT"
));
}
public
static
String
getTimestamp
()
{
return
iso8601Format
.
format
(
new
Date
());
}
public
static
String
toString
(
Calendar
cal
)
{
if
(
cal
==
null
)
{
return
(
null
);
}
return
toString
(
cal
.
getTime
());
}
public
static
synchronized
String
toString
(
Date
date
)
{
if
(
date
==
null
)
{
return
(
null
);
}
return
iso8601OutputFormat
.
format
(
date
);
}
public
static
Date
toDate
(
String
dateTimeString
)
throws
ParseException
{
if
(
dateTimeString
==
null
)
{
return
(
null
);
}
dateTimeString
=
dateTimeString
.
trim
();
SimpleDateFormat
fmt
;
if
(
dateTimeString
.
length
()
>
10
)
{
fmt
=
(
dateTimeString
.
charAt
(
10
)
==
'T'
?
(
dateTimeString
.
endsWith
(
"Z"
)
?
iso8601OutputFormat
:
iso8601Format
)
:
iso8601AlternateFormat
);
}
else
{
fmt
=
iso8601Format
;
}
synchronized
(
fmt
)
{
return
(
fmt
.
parse
(
dateTimeString
));
}
}
public
static
Calendar
toCalendar
(
String
dateTimeString
)
throws
ParseException
{
Date
date
=
toDate
(
dateTimeString
);
Calendar
cal
=
Calendar
.
getInstance
();
cal
.
setTime
(
date
);
return
(
cal
);
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment