Common time and date processing classes
Cycas
Tieshu
Rngguliu@163.com
Monday, April 3, 2006
In the development of Jsp/j2ee/java, a number of date and time conversions are often used, and some methods that are often used are packaged together for ease of use.
1 class dateutils Overview
Overview of methods
|
Static String |
adddate (string strdate, int days)//Convert date string to new date string
|
Static String |
Getdatecs ()///Get current date (China, yyyy mm month DD day)
|
Static String |
Getdateid ()////with the current date as the file name, generally do not duplicate the value is from the current time string format, with microseconds, recommended as the record ID.
|
Static String |
GetFileName ()///with the current date as the file name, generally does not duplicate the value is the number of milliseconds from January 1, 1970 starting from 00:00:00.
|
Static String |
Getlongstr ()//Get the long string form of the current time "Yyyy-mm-dd HH:mm:ss"
|
Static String |
Getlongstr (date date)//Gets the long string form of a given time "Yyyy-mm-dd HH:mm:ss"
|
Static String |
Getlongstr (int D)//Get the present moment of D days; Long string form "Yyyy-mm-dd HH:mm:ss"
|
Static Date |
Getnow ()//Get the current time
|
Static String |
Getshortstr ()//Get the current time short string form "YYYY-MM-DD"//Must be uppercase MM (month)
|
Static String |
Getshortstr (date date)//Get short string form "Yyyy-mm-dd" for a given time
|
Static String |
GETWEEKCS ()//Get Current week (China, such as: Sunday, Monday, Tuesday)
|
Static Date |
tolongdate (String strdate)
Converts a string to a long format for general time: Yyyy-mm-dd HH:MM:SS
|
Static Date |
toshortdate (string strdate)//A short form that converts a string to a general time; Yyyy-mm-dd
|
2JSP Invoke Instance
<%@ page contenttype= "TEXT/HTML;CHARSET=GBK"%>
<%=general. DATEUTILS.GETWEEKCS ()%><br>
<%=general. Dateutils.getdatecs ()%><br>
<%=general. Dateutils.getlongstr ()%><br>
<%=general. DATEUTILS.GETLONGSTR (2)%><br>
<%=general. Dateutils.getdateid ()%><br>
<%=general. Dateutils.getfilename ()%><br>
</body>
Output:
Monday
April 03, 2006
2006-04-03 21:23:45
2006-04-05 21:23:45
20060403212345508
1144070625508
3 class dateutils Source code:
/**
* @author Cycas
* Methods for dealing with time and date
*/