public class DateUtils extends Object
| Modifier and Type | Field and Description |
|---|---|
static int |
MAX_INT_CHAR_WIDTH |
static String |
VERSION |
| Constructor and Description |
|---|
DateUtils() |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
byteArrayEquals(byte[] lhs,
byte[] rhs)
check that two byte arrays are equal.
|
static String |
doubleToString(double val,
int maxFractionDigits)
Converts a double to a string.
|
static String |
formatBytesForDisplay(long amount)
Takes a byte size and formats it for display with 'friendly' units.
|
static String |
formatMillisecondsToConventional(long time)
Convert milliseconds value to a human-readable duration
|
static String |
formatMillisecondsToConventional(long duration,
int unitCount)
Convert milliseconds value to a human-readable duration of
mixed units, using units no larger than days.
|
static String |
get12DigitDate()
Utility function for creating 12-digit(no seconds!) date stamps
in the format yyyyMMddHHmm.
|
static String |
get12DigitDate(Date d)
Utility function for creating 12-digit(no seconds!) date stamps
in the format yyyyMMddHHmm.
|
static String |
get12DigitDate(long date)
Utility function for creating 12-digit(no seconds!) date stamps
in the format yyyyMMddHHmm.
|
static String |
get14DigitDate()
Utility function for creating arc-style date stamps
in the format yyyyMMddHHmmss.
|
static String |
get14DigitDate(Date d)
Utility function for creating arc-style date stamps
in the format yyyyMMddHHmmss.
|
static String |
get14DigitDate(long date)
Utility function for creating arc-style date stamps
in the format yyyyMMddHHmmss.
|
static String |
get17DigitDate()
Utility function for creating arc-style date stamps
in the format yyyMMddHHmmssSSS.
|
static String |
get17DigitDate(Date date)
Utility function for creating warc-style date stamps
in the format yyyyMMddHHmmssSSS.
|
static String |
get17DigitDate(long date)
Utility function for creating warc-style date stamps
in the format yyyyMMddHHmmssSSS.
|
static Date |
getDate(String d)
Parses an ARC-style date.
|
static String |
getLog14Date()
Utility function for creating log timestamps, in
W3C/ISO8601 format, assuming UTC.
|
static String |
getLog14Date(Date date)
Utility function for creating log timestamps, in
W3C/ISO8601 format, assuming UTC.
|
static String |
getLog14Date(long date)
Utility function for creating log timestamps, in
W3C/ISO8601 format, assuming UTC.
|
static String |
getLog17Date()
Utility function for creating log timestamps, in
W3C/ISO8601 format, assuming UTC.
|
static String |
getLog17Date(Date date)
Utility function for creating log timestamps, in
W3C/ISO8601 format, assuming UTC.
|
static String |
getLog17Date(long date)
Utility function for creating log timestamps, in
W3C/ISO8601 format, assuming UTC.
|
static String |
getRFC1123Date(Date date)
Utility function for creating HTTP header style date strings,
specifically, RFC 1123: EEE, dd MMM yyyy HH:mm:ss z.
|
static Date |
getSecondsSinceEpoch(String timestamp) |
static String |
getUnique14DigitDate()
Utility function for creating UNIQUE-from-this-class
arc-style date stamps in the format yyyMMddHHmmss.
|
static String |
padTo(int i,
int pad)
Convert an
int to a String, and pad it to
pad spaces. |
static String |
padTo(String s,
int pad)
Pad the given
String to pad characters wide
by pre-pending spaces. |
static String |
padTo(String s,
int pad,
char padChar)
Pad the given
String to pad characters wide
by pre-pending padChar. |
static Date |
parse12DigitDate(String date)
Utility function for parsing arc-style date stamps
in the format yyyMMddHHmm.
|
static Date |
parse14DigitDate(String date)
Utility function for parsing arc-style date stamps
in the format yyyMMddHHmmss.
|
static Date |
parse17DigitDate(String date)
Utility function for parsing arc-style date stamps
in the format yyyMMddHHmmssSSS.
|
static String |
secondsSinceEpoch(String timestamp) |
static String |
zeroPadInteger(int i) |
public static final String VERSION
public static int MAX_INT_CHAR_WIDTH
public static String getRFC1123Date(Date date)
public static String get17DigitDate()
public static String get17DigitDate(long date)
date - milliseconds since epocpublic static String get17DigitDate(Date date)
date - Date objectpublic static String get14DigitDate()
public static String get14DigitDate(long date)
date - milliseconds since epocpublic static String get14DigitDate(Date d)
date - Date for timestamppublic static String get12DigitDate()
public static String get12DigitDate(long date)
date - milliseconds since epocpublic static String get12DigitDate(Date d)
date - Date object to formatpublic static String getLog17Date()
public static String getLog17Date(long date)
date - milliseconds since epoc.public static String getLog17Date(Date date)
date - Date to format.public static String getLog14Date()
public static String getLog14Date(long date)
date - long timestamp to format.public static String getLog14Date(Date date)
date - Date to format.public static Date getDate(String d) throws ParseException
A - 4-17 digit date in ARC style (yyyy to
yyyyMMddHHmmssSSS) formatting.ParseExceptionpublic static Date parse17DigitDate(String date) throws ParseException
date - an arc-style formatted date stampParseException - if the inputstring was malformedpublic static Date parse14DigitDate(String date) throws ParseException
date - an arc-style formatted date stampParseException - if the inputstring was malformedpublic static Date parse12DigitDate(String date) throws ParseException
date - an arc-style formatted date stampParseException - if the inputstring was malformedpublic static String secondsSinceEpoch(String timestamp) throws ParseException
timestamp - A 14-digit timestamp or the suffix for a 14-digit
timestamp: E.g. '20010909014640' or '20010101' or '1970'.ParseExceptionpublic static Date getSecondsSinceEpoch(String timestamp) throws ParseException
timestamp - A 14-digit timestamp or the suffix for a 14-digit
timestamp: E.g. '20010909014640' or '20010101' or '1970'.ParseExceptionsecondsSinceEpoch(String)public static String zeroPadInteger(int i)
i - Integer to add prefix of zeros too. If passed
2005, will return the String 0000002005. String
width is the width of Integer.MAX_VALUE as a string (10
digits).i.public static String padTo(int i, int pad)
int to a String, and pad it to
pad spaces.i - the intpad - the width to pad to.public static String padTo(String s, int pad)
String to pad characters wide
by pre-pending spaces. s should not be null.
If s is already wider than pad no change is
done.s - the String to padpad - the width to pad to.public static String padTo(String s, int pad, char padChar)
String to pad characters wide
by pre-pending padChar.
s should not be null. If s is
already wider than pad no change is done.s - the String to padpad - the width to pad to.padChar - The pad character to use.public static boolean byteArrayEquals(byte[] lhs,
byte[] rhs)
null.lhs - a byte arrayrhs - another byte array.true if they are both equal (or both
null)public static String doubleToString(double val, int maxFractionDigits)
val - The double to convertprecision - How many characters to include after '.'public static String formatBytesForDisplay(long amount)
This involves converting it to the largest unit (of B, KiB, MiB, GiB, TiB) for which the amount will be > 1.
Additionally, at least 2 significant digits are always displayed.
Negative numbers will be returned as '0 B'.
amount - the amount of bytespublic static String formatMillisecondsToConventional(long time)
time - timepublic static String formatMillisecondsToConventional(long duration, int unitCount)
duration - unitCount - how many significant units to show, at most
for example, a value of 2 would show days+hours or hours+seconds
but not hours+second+millisecondstimepublic static String getUnique14DigitDate()
Copyright © 2015 The International Internet Preservation Consortium. All Rights Reserved.