org.eclipse.stardust.common
Class DateUtils

java.lang.Object
  extended by org.eclipse.stardust.common.DateUtils

public class DateUtils
extends Object

This utility class provides convenience methods for date / time related conversions and checks.

Version:
$Revision$
Author:
ubirkemeyer

Constructor Summary
DateUtils()
           
 
Method Summary
static Date businessDateToDate(Calendar cal)
           
static long businessDateToTimestamp(Calendar cal)
           
static Calendar dateToBusinessDate(Date businessDate)
           
static String formatDate(Date date)
          Returns a String representation for given Date object using date formatter with default style for default locale.
static String formatDateTime(Date date)
          Returns a String representation for given Date object.
static String formatDurationAsString(double durationInHours)
          Returns the given duration in hours as formatted string.
Format is: hours:minutes:seconds h
Example : 1:05:20 h
static String formatTime(Date date)
          Returns a String representation for given Date object using time formatter with default style for default locale.
static SimpleDateFormat getInteractiveDateFormat()
          Factory which creates a SimpleDateFormat instance which can be used to format Dates to strings with pattern "yyyy/MM/dd hh:mm:ss".
static SimpleDateFormat getNoninteractiveDateFormat()
          Factory which creates a SimpleDateFormat instance which can be used to format Dates to strings with pattern "yyyy/MM/dd hh:mm:ss:SSS".
static long getTimestamp(Date date, long def)
          Returns number of milliseconds since January 1, 1970, 00:00:00 GMT represented by given Date object.
static boolean isValidISODateFormat(String date)
          Checks if the input date conforms to an ISO date pattern (e.g.
static boolean isValidNonInteractiveFormat(String date)
          Checks if the input date conforms to the non-interactive date format yyyy/MM/dd hh:mm:ss:SSS.
static void resetTimeComponent(Calendar calendar)
           
static Calendar timestampToBusinessDate(long timestamp)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DateUtils

public DateUtils()
Method Detail

getNoninteractiveDateFormat

public static SimpleDateFormat getNoninteractiveDateFormat()
Factory which creates a SimpleDateFormat instance which can be used to format Dates to strings with pattern "yyyy/MM/dd hh:mm:ss:SSS".

Returns:
the SimpleDateFormat instance
See Also:
SimpleDateFormat

getInteractiveDateFormat

public static SimpleDateFormat getInteractiveDateFormat()
Factory which creates a SimpleDateFormat instance which can be used to format Dates to strings with pattern "yyyy/MM/dd hh:mm:ss".

Returns:
the SimpleDateFormat instance
See Also:
SimpleDateFormat

getTimestamp

public static long getTimestamp(Date date,
                                long def)
Returns number of milliseconds since January 1, 1970, 00:00:00 GMT represented by given Date object. If Date object is null the default value will be returned.

Parameters:
date - the Date object.
def - the default value used if Date object is null.
Returns:
number of milliseconds since January 1, 1970, 00:00:00 GMT.
See Also:
Date.getTime()

formatDateTime

public static String formatDateTime(Date date)
Returns a String representation for given Date object. The String is a concatenation of date formatter and time formatter separated by single space, both using default style for default locale.

Parameters:
date - the Date object.
Returns:
String representation for Date object using default style for default locale. For null Date object an empty String will be returned.
See Also:
DateFormat.getDateInstance(), DateFormat.getTimeInstance()

formatDate

public static String formatDate(Date date)
Returns a String representation for given Date object using date formatter with default style for default locale.

Parameters:
date - the Date object.
Returns:
String representation of date component for Date object using default style for default locale. For null Date object an empty String will be returned.
See Also:
DateFormat.getDateInstance()

formatTime

public static String formatTime(Date date)
Returns a String representation for given Date object using time formatter with default style for default locale.

Parameters:
date - the Date object.
Returns:
String representation of time component for Date object using default style for default locale. For null Date object an empty String will be returned.
See Also:
DateFormat.getTimeInstance()

formatDurationAsString

public static String formatDurationAsString(double durationInHours)
Returns the given duration in hours as formatted string.
Format is: hours:minutes:seconds h
Example : 1:05:20 h

Parameters:
durationInHours - the duration in hours.
Returns:
String representation of duration.

isValidISODateFormat

public static boolean isValidISODateFormat(String date)
Checks if the input date conforms to an ISO date pattern (e.g. yyyy-MM-dd HH:mm:ss:SSS).

Parameters:
date - String representation of date.
Returns:
true if the date conforms to an ISO date pattern, false if it does not conform

isValidNonInteractiveFormat

public static boolean isValidNonInteractiveFormat(String date)
Checks if the input date conforms to the non-interactive date format yyyy/MM/dd hh:mm:ss:SSS.

Parameters:
date - String representation of date.
Returns:
true if the date conforms to this pattern, false if it does not conform

resetTimeComponent

public static void resetTimeComponent(Calendar calendar)

businessDateToTimestamp

public static long businessDateToTimestamp(Calendar cal)

businessDateToDate

public static Date businessDateToDate(Calendar cal)

dateToBusinessDate

public static Calendar dateToBusinessDate(Date businessDate)

timestampToBusinessDate

public static Calendar timestampToBusinessDate(long timestamp)


Copyright © 2017 Eclipse Stardust. All Rights Reserved.