diff options
| author | Paul Buetow <paul@buetow.org> | 2009-02-18 23:01:21 +0000 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2009-02-18 23:01:21 +0000 |
| commit | 89c679eb813611a2ede208b4c8e27c7f596b3be7 (patch) | |
| tree | f44c19435286e78b9e8002990e1b55183a4fbc49 /sources/shared/MyDate.java | |
| parent | 177f346a9bbe455dc12fd26dfa2c586585c28c1e (diff) | |
added copyright to header
Diffstat (limited to 'sources/shared/MyDate.java')
| -rw-r--r-- | sources/shared/MyDate.java | 88 |
1 files changed, 46 insertions, 42 deletions
diff --git a/sources/shared/MyDate.java b/sources/shared/MyDate.java index 00bf59d..f1f54fe 100644 --- a/sources/shared/MyDate.java +++ b/sources/shared/MyDate.java @@ -1,3 +1,7 @@ +/* NetCalendar 2006, 2009 (c) Dipl.-Inform. (FH) Paul C. Buetow + * http://netcalendar.buetow.org - netcalendar@dev.buetow.org + */ + package shared; import java.util.*; @@ -9,46 +13,46 @@ import java.util.*; * */ public class MyDate extends Date { - private final static long serialVersionUID = 1L; - private final static String [] DAYS = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; - - /** - * Copy constructor. - * @param data Specifies the date objekt to copy the time from. - */ - public MyDate(Date date) { - super(date.getTime()); - } - - /** - * @see java.lang.Object#toString() - */ - public String toString() { - Calendar calendar = Calendar.getInstance(); - calendar.setTime(this); - - String sYear = addZerosToFront(calendar.get(Calendar.YEAR), 4); - String sMonth = addZerosToFront(calendar.get(Calendar.MONTH) + 1, 2); - String sDays = addZerosToFront(calendar.get(Calendar.DAY_OF_MONTH), 2); - String sHours= addZerosToFront(calendar.get(Calendar.HOUR), 2); - String sMinutes = addZerosToFront(calendar.get(Calendar.MINUTE), 2); - String sDay = DAYS[calendar.get(Calendar.DAY_OF_WEEK)-1]; - - return sDays + "." + sMonth + "." + sYear + " " + sHours + ":" + sMinutes + " " + sDay; - } - - /** - * This method adds zeros in front of a number and returns it as a string. - * @param iValue Specifies the number to add zeros to. - * @param iWantedLength Specifies the wanted max length of the string. - * @return Returns the number represented as a string with additional zeros on front. - */ - public static String addZerosToFront(int iValue, int iWantedLength) { - String sValue = iValue + ""; - - while (sValue.length() < iWantedLength) - sValue = "0" + sValue; - - return sValue; - } + private final static long serialVersionUID = 1L; + private final static String [] DAYS = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; + + /** + * Copy constructor. + * @param data Specifies the date objekt to copy the time from. + */ + public MyDate(Date date) { + super(date.getTime()); + } + + /** + * @see java.lang.Object#toString() + */ + public String toString() { + Calendar calendar = Calendar.getInstance(); + calendar.setTime(this); + + String sYear = addZerosToFront(calendar.get(Calendar.YEAR), 4); + String sMonth = addZerosToFront(calendar.get(Calendar.MONTH) + 1, 2); + String sDays = addZerosToFront(calendar.get(Calendar.DAY_OF_MONTH), 2); + String sHours= addZerosToFront(calendar.get(Calendar.HOUR), 2); + String sMinutes = addZerosToFront(calendar.get(Calendar.MINUTE), 2); + String sDay = DAYS[calendar.get(Calendar.DAY_OF_WEEK)-1]; + + return sDays + "." + sMonth + "." + sYear + " " + sHours + ":" + sMinutes + " " + sDay; + } + + /** + * This method adds zeros in front of a number and returns it as a string. + * @param iValue Specifies the number to add zeros to. + * @param iWantedLength Specifies the wanted max length of the string. + * @return Returns the number represented as a string with additional zeros on front. + */ + public static String addZerosToFront(int iValue, int iWantedLength) { + String sValue = iValue + ""; + + while (sValue.length() < iWantedLength) + sValue = "0" + sValue; + + return sValue; + } } |
