Date Format String specification, Format String Specification

Source: Internet
Author: User
Tags dateformat

Date Format String specification, Format String Specification


From http://yanwushu.sinaapp.com /? P = 16

Yyyy-MM-dd HH: mm: ss is a date formatted string. This document describes the specifications of this string.


Case sensitivity

Yyyy-MM-dd HH: mm: ss year-month-day hour: minute: Second

M is case-sensitive to distinguish between "month" and "Minute"

H is case-sensitive to distinguish between 12-hour and 24-hour. h in lower case is 12-hour, and H in upper case is 24-hour.


Repeated

Sometimes we will see the format: yyyy-M-d H: m: s

Mm and m, the difference between them isWhether there is a leading zero: H, m, sNon-zero start, HH, mm, ss indicatesStarting from scratch.

For example, at 01:02 a.m., HH: mm is displayed0:02, H: m is displayed.

Let's take the example of 01:01:01 (Wednesday) on March 13, January 1, 2014 as an example to introduce other things:

Yyyy/yyy/yy/yDisplayed2014/2014 /14/4(3 y is the same as 4 y. For ease of understanding, write 4 y more)

MMMM/MMM/MM/MDisplayedJanuary/01/1

(The full names of 4 MB and 3 MB are displayed. However, the Chinese characters are the same. The English letters are January and Jan)

Dddd/ddd/dd/dDisplayedWednesday/Wednesday(Some languages are displayed as "3 ")/01/1

(Like M in English, 4 d is the full name and 3 is the short name;

Dddd/ddd indicates the day of the week, and dd/d indicates the number of days)

HH/H/hh/hDisplayed01/1/01 AM/1 AM

The restMm/m/ss/sIt's just a matter of leading zero.

Yyyy/M/d/dddd H: mm: ss is 1:01:01 on Wednesday, January 1, January 1, 2014.


Note:

The writing format is related to the language requirements. The above is a common writing method in Windows, including setting the date in office software. There are similar expressions in other languages but they use different symbols or formats.

 


Formatting and calculation of the string date specified by java

/*
* For example, two characters, 08:30:00 and 17:50:00, are given.
* How To Format String dates and calculate the number of different hours!
* You cannot enter a date that does not exist after the test. For example, change the date by yourself.
*/
Import java. io. BufferedReader;
Import java. io. IOException;
Import java. io. InputStreamReader;
Import java. text. ParseException;
Import java. text. SimpleDateFormat;
Import java. util. Date;

Public class DateCal {
Private String first = "";
Private String second = "";
Private Date firstDate = null;
Private Date secondDate = null;
Private boolean flag = true;

Public static void main (String [] args ){
New DateCal (). message ();

}

Private void message (){
Do {
Flag = true;
System. out. println ("Enter the first date :");
First = input ();
FirstDate = dateFormat (first );
} While (false = flag );
Do {
Flag = true;
System. out. println ("enter the second date :");
Second = input ();
SecondDate = dateFormat (second );
} While (false = flag );
Long hours = secondDate. getTime ()-firstDate. getTime ();
System. out. println ("hours of Difference:" + hours/(60*60*1000 ));
}

Private String input (){
String s = "";
Do {
Flag = true;
Try {
InputStreamReader isr = new InputStreamReader (System. in );
BufferedReader br = new BufferedReader (isr );
S = br. readLine ();
} Catch (IOException e ){
System. out. println ("the input is invalid. ");
}
} While (false = flag );
Return s;
}

Private Date dateFormat (String format ){
Date date = null;
Try {
Date = new SimpleDat... the remaining full text>

Asp format date string output

<%
'User-defined functions
Function GMTtime (a, B, c)

Dim xx2wVar, xx2wToWeek, xx2wToMonth
Xx2wVar = a & "-" & B & "-" & c
If Not IsDate (xx2wVar) Then
Xx2wVar = Now
Else
Xx2wVar = CDate (xx2wVar)
End If
Xx2wToWeek = Array ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat ")
Xx2wToMonth = Array ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep ", "Oct", "Nov", "Dec ")
GMTtime = xx2wToWeek (Weekday (xx2wVar)-1) & "& right (xx2wAs & Day (xx2wVar), 2) &"-"& xx2wToMonth (Month (xx2wVar)-1) & "-" & Year (xx2wVar)
End Function

'Usage

Response. write GMTtime (2009, 5, 13)
%>

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.