Common time and date processing classes

Source: Internet
Author: User
Tags string format time and date

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 constructors

dateutils ()            

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

*/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.