Diamond Control Suite 3.0

diamondedge.util
Class DateTime

java.lang.Object
  extended by diamondedge.util.DateTime

public class DateTime
extends Object

Utility functions to manipulate Date and Calendar objects


Field Summary
static Date EmptyDate
           
static int USE_SYSTEM_DAY_OF_WEEK
           
 
Constructor Summary
DateTime()
           
 
Method Summary
static Date add(Date date1, Date date2)
           
static Date add(Date date1, double daysToAdd)
          Returns a date the specified, daysToAdd, number of days after the date, date1
static Date add(int field, int number, Date date)
          Returns a date to which a specified time field has been added
static Date add(String interval, int number, Date date)
          Returns a date to which a specified time interval has been added
static int compare(Date date1, Date date2)
          returns 0 if date1 is the same date as date2 returns 1 if date1 is after (greater than) date2 returns -1 if date1 is before (less than) date2
static int datePart(String interval, Date date)
          Returns a specified part of the given date
static int datePart(String interval, Date date, int firstDayOfWeek, int FirstWeekOfYear)
          Returns a specified part of the given date
static Date dateSerial(int year, int month, int day)
           
static int day(Date date)
          Returns a whole number representing the day of the week
static int dayOfYear(Date date)
          Returns a whole number representing the day of the year
static double diff(Date date1, Date date2)
          Returns a double representing the fractional number of days between the two dates.
static int diff(String interval, Date date1, Date date2)
          Returns the number of time intervals between two dates.
static int diff2(Date date1, Date date2, String interval)
          Returns the number of time intervals between two dates.
static String format(Date d)
          Returns an expression formatted as a date and/or time.
static String format(Date d, String format)
           
static String format(Date d, String format, int firstDayOfWeek)
          returns the formated string for the given date.
static String format(String dateToParse, String format)
           
static String format(Variant expr, String format)
           
static String formatDateTime(Date d)
          Deprecated.  
static Calendar getCalendar(Date date)
           
static int hour(Date date)
          Returns a whole number representing the hour of the day
static int minute(Date date)
          Returns a whole number representing the minute
static int month(Date date)
          Returns a whole number representing the month
static String monthName(int Month, boolean Abbreviate)
          Returns localized month name
static Date now()
          Returns the current system date and time
static int second(Date date)
          Returns a whole number representing the second
static void setDefaultDateFormat(DateFormat f)
          Sets the default format used to convert dates to strings when only the date portion is set.
static void setDefaultDateTimeFormat(DateFormat f)
          Sets the default format used to convert dates to strings when the date and time portions are set.
static void setDefaultTimeFormat(DateFormat f)
          Sets the default format used to convert dates to strings when only the time portion is set.
static Date subtract(Date date1, double daysToSubtract)
          Returns a date the specified, daysToSubtract, number of days before the date, date1
static float timer()
          Returns the number of seconds elapsed since midnight
static Date timeSerial(int hour, int minute, int second)
          Returns a date containing the time for a specific hour, minute and second
static Date toDate(double dbl)
          returns a date for the given day since Dec 30, 1899 Note: the fractional part represents the time of day in relation to current timezone.
static Date toDate(String str)
           
static Date toDate2(String str)
           
static double toDouble(Date date)
          returns a double representing the number of days since Dec 30, 1899 Note: the fractional part represents the time of day in relation to current timezone.
static int toInt(Date date)
          returns an integer representing the number of days since Dec 30, 1899
static int weekday(Date date, int firstDayOfWeek)
          Returns a whole number representing the day of the week
static int weekday2(Date date, int returnType)
          Returns the day of the week corresponding to a date.
static String weekdayName(int Weekday, boolean Abbreviate, int firstDayOfWeek)
          Returns localized weekday name
static int weekOfYear(Date date, int firstDayOfWeek)
          Returns the week of the year corresponding to a date.
static int year(Date date)
          Returns a whole number representing the year
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

USE_SYSTEM_DAY_OF_WEEK

public static final int USE_SYSTEM_DAY_OF_WEEK
See Also:
Constant Field Values

EmptyDate

public static final Date EmptyDate
Constructor Detail

DateTime

public DateTime()
Method Detail

getCalendar

public static final Calendar getCalendar(Date date)

compare

public static final int compare(Date date1,
                                Date date2)
returns 0 if date1 is the same date as date2 returns 1 if date1 is after (greater than) date2 returns -1 if date1 is before (less than) date2


toInt

public static final int toInt(Date date)
returns an integer representing the number of days since Dec 30, 1899


toDouble

public static final double toDouble(Date date)
returns a double representing the number of days since Dec 30, 1899 Note: the fractional part represents the time of day in relation to current timezone.


toDate

public static final Date toDate(double dbl)
returns a date for the given day since Dec 30, 1899 Note: the fractional part represents the time of day in relation to current timezone.


toDate

public static final Date toDate(String str)
                         throws ParseException
Throws:
ParseException

toDate2

public static final Date toDate2(String str)

now

public static Date now()
Returns the current system date and time


add

public static Date add(String interval,
                       int number,
                       Date date)
Returns a date to which a specified time interval has been added


add

public static Date add(int field,
                       int number,
                       Date date)
Returns a date to which a specified time field has been added


add

public static Date add(Date date1,
                       Date date2)

add

public static Date add(Date date1,
                       double daysToAdd)
Returns a date the specified, daysToAdd, number of days after the date, date1


subtract

public static Date subtract(Date date1,
                            double daysToSubtract)
Returns a date the specified, daysToSubtract, number of days before the date, date1


diff

public static int diff(String interval,
                       Date date1,
                       Date date2)
Returns the number of time intervals between two dates. Note: positive value returned when date2 > date1

Parameters:
interval - --------------- Interval Description yyyy Returns the number of years. q Returns the number of quarters. m Returns the number of months. y Returns the number of days. d Returns the number of days. w Returns the number of days. ww Returns the number of weeks. h Returns the number of hours. n Returns the number of minutes. s Returns the number of seconds.

diff2

public static int diff2(Date date1,
                        Date date2,
                        String interval)
Returns the number of time intervals between two dates. Note: positive value returned when date2 > date1. This is the excel compatible version of DateDif.

Parameters:
interval - --------------- Interval Description y Returns the number of years. m Returns the number of months. d Returns the number of days. ym Returns the number of months (day and year ignored). yd Returns the number of days (year ignored). md Returns the number of days (month and year ignored).

diff

public static double diff(Date date1,
                          Date date2)
Returns a double representing the fractional number of days between the two dates. Note: positive value returned when date2 > date1


year

public static int year(Date date)
Returns a whole number representing the year


month

public static int month(Date date)
Returns a whole number representing the month


day

public static int day(Date date)
Returns a whole number representing the day of the week


dayOfYear

public static int dayOfYear(Date date)
Returns a whole number representing the day of the year


weekday

public static int weekday(Date date,
                          int firstDayOfWeek)
Returns a whole number representing the day of the week

Parameters:
firstDayOfWeek - 0 means use default calendar, otherwise use Calendar constants such as Calendar.SUNDAY

weekday2

public static int weekday2(Date date,
                           int returnType)
Returns the day of the week corresponding to a date.

Parameters:
date - date to extract the day of week from.
returnType - One of:
  • 0 - returns day for default calendar
  • 1 - returns 1 (Sunday) through 7 (Saturday)
  • 2 - returns 1 (Monday) through 7 (Sunday)
  • 3 - returns 0 (Monday) through 6 (Sunday)

weekOfYear

public static int weekOfYear(Date date,
                             int firstDayOfWeek)
Returns the week of the year corresponding to a date. The first week is 1.

Parameters:
date - date to extract the day of week from.
firstDayOfWeek - One of:
  • 0 - returns week for default calendar
  • 1 - week begins on Sunday
  • 2 - week begins on Monday

hour

public static int hour(Date date)
Returns a whole number representing the hour of the day


minute

public static int minute(Date date)
Returns a whole number representing the minute


second

public static int second(Date date)
Returns a whole number representing the second


timer

public static float timer()
Returns the number of seconds elapsed since midnight


dateSerial

public static Date dateSerial(int year,
                              int month,
                              int day)

timeSerial

public static Date timeSerial(int hour,
                              int minute,
                              int second)
Returns a date containing the time for a specific hour, minute and second


datePart

public static int datePart(String interval,
                           Date date,
                           int firstDayOfWeek,
                           int FirstWeekOfYear)
Returns a specified part of the given date


datePart

public static int datePart(String interval,
                           Date date)
Returns a specified part of the given date


formatDateTime

public static String formatDateTime(Date d)
Deprecated. 

Returns an expression formatted as a date and/or time.


format

public static String format(Date d)
Returns an expression formatted as a date and/or time.


setDefaultDateFormat

public static void setDefaultDateFormat(DateFormat f)
Sets the default format used to convert dates to strings when only the date portion is set.

See Also:
format(java.util.Date)

setDefaultTimeFormat

public static void setDefaultTimeFormat(DateFormat f)
Sets the default format used to convert dates to strings when only the time portion is set.

See Also:
format(java.util.Date)

setDefaultDateTimeFormat

public static void setDefaultDateTimeFormat(DateFormat f)
Sets the default format used to convert dates to strings when the date and time portions are set.

See Also:
format(java.util.Date)

weekdayName

public static String weekdayName(int Weekday,
                                 boolean Abbreviate,
                                 int firstDayOfWeek)
Returns localized weekday name


monthName

public static String monthName(int Month,
                               boolean Abbreviate)
Returns localized month name


format

public static String format(Date d,
                            String format,
                            int firstDayOfWeek)
returns the formated string for the given date. Note: firstDayOfWeek argument is not supported
Note: Make sure you change N to m, Nn to mm, m to M, mm to MM and mmm to MMM

Note: You should change your VB code for user-defined formats to use the codes underneath the Java column. All but the E, EEEE, and a will also work the same in VB.

Named Date/Time Formats
-----------------------
General Date    Display a date and/or time. For real numbers, display a date and time, for example, 4/3/93 05:34 PM.If there is no fractional part, display only a date, for example, 4/3/93. If there is no integer part, display time only, for example, 05:34 PM. Date display is determined by your system settings.
Long Date       Display a date according to your system's long date format.
Medium Date     Display a date using the medium date format appropriate for the language version of thehost application.
Short Date      Display a date using your system's short date format.
Long Time       Display a time using your system's long time format; includes hours, minutes, seconds.
Medium Time     Display time in 12-hour format using hours and minutes and the AM/PM designator.
Short Time      Display a time using the 24-hour format, for example, 17:45.

User-defined Date/Time Formats
------------------------------
VB      Java  Description
(:)           Time separator. In somelocales, other characters may be used to represent the time separator. The time separator separates hours, minutes, and seconds when time values are formatted. The actual character used as the time separator in formatted output is determined by your system settings.
(/)           Date separator. In some locales, other characters may be used to represent the date separator. The date separator separates the day, month, and year when date values are formatted. The actual character used as the date separator in formatted output is determined by your system settings.
c             Display the date as ddddd and display the time as ttttt, in that order. Display only date information if there is no fractional part to the date serial number; display only time information if there is no integer portion.
d       d     Display the day as a number without a leading zero (1 to 31).
dd      dd    Display the day as a number with a leading zero (01 to 31).
ddd     E     Display the day as an abbreviation (Sun to Sat).
dddd    EEEE  Display the day as a full name (Sunday to Saturday).
ddddd         Display the date as a complete date (including day, month, and year), formatted according to your system's short date format setting. The default short date format is m/d/yy.
dddddd        Display a date serial number as a complete date (including day, month, and year) formatted according to the long date setting recognized by your system. The default long date format is mmmm dd, yyyy.
w             Display the day of the week as a number (1 for Sunday through 7 for Saturday).
ww      w     Display the week of the year as a number (1 to 54).
m       M     Display the month as a number without a leading zero (1 to 12). If m immediately follows h or hh, the minute rather than the month is displayed.
mm      MM    Display the month as a number with a leading zero (01 to 12). If m immediately follows h or hh, the minute rather than the month is displayed.
mmm     MMM   Display the month as an abbreviation (Jan to Dec).
mmmm    MMMM  Display the month as a full month name (January to December).
q             Display the quarter of the year as a number (1 to 4).
y       D     Display the day of the year as a number (1 to 366).
yy      yy    Display the year as a 2-digit number (00 to 99).
yyyy    yyyy  Display the year as a 4-digit number (100 to 9999).
h       h     Display the hour as a number without leading zeros (0 to 12).
Hh      hh    Display the hour as a number with leading zeros (00 to 12).
h       H     Display the hour as a number without leading zeros (0 to 23).
Hh      HH    Display the hour as a number with leading zeros (00 to 23).
N       m     Display the minute as a number without leading zeros (0 to 59).
Nn      mm    Display the minute as a number with leading zeros (00 to 59).
S       s     Display the second as a number without leading zeros (0 to 59).
Ss      ss    Display the second as a number with leading zeros (00 to 59).
ttttt         Display a time as a complete time (including hour, minute, and second), formatted using the time separator defined by the time format recognized by your system. A leading zero is displayed if the leading zero option is selected and the time is before 10:00 A.M. or P.M. The default time format is h:mm:ss.
AM/PM   a     Use the 12-hour clock and display an uppercase AM with any hour before noon; display an uppercase PM with any hour between noon and 11:59 P.M.
am/pm   a     Use the 12-hour clock and display a lowercase AM with any hour before noon; display a lowercase PM with any hour between noon and 11:59 P.M.
A/P     a     Use the 12-hour clock and display an uppercase A with any hour before noon; display an uppercase P with any hour between noon and 11:59 P.M.
a/p     a     Use the 12-hour clock and display a lowercase A with any hour before noon; display a lowercase P with any hour between noon and 11:59 P.M.
AMPM    a     Use the 12-hour clock and display the AMstring literal as defined by your system with any hour before noon; display the PM string literal as defined by your system with any hour between noon and 11:59 P.M. AMPM can be either uppercase or lowercase, but the case of the string displayed matches the string as defined by your system settings. The default format is AM/PM.


format

public static String format(Date d,
                            String format)
See Also:
format( Date d, String format, int firstDayOfWeek )

format

public static String format(String dateToParse,
                            String format)
See Also:
format( Date d, String format, int firstDayOfWeek )

format

public static String format(Variant expr,
                            String format)
See Also:
format( Date d, String format, int firstDayOfWeek )

Diamond Control Suite 3.0

Diamond Edge and Diamond Control Suite are trademarks or registered trademarks of Diamond Edge, Inc. Copyright 1999-2005 Diamond Edge, Inc. All Rights Reserved.