SIMPLEDATEFORMAT function example

xiaoxiao2021-03-05  28

Public class

SimpleDateFormat Extends DateFormat

SimpleDateFormat is a specific class that formats and analyzes data in country-sensitive ways. It allows formatted (DATE -> Text), syntax analysis (Text -> Date) and standardization.

SimpleDateFormat allows for the date-time formatting to select any user-specified way to start. However, I hope to create a date-time formatting program with GetTimeInstance, GetDateInstance or GetDateTimeInstance in DateFormat. Each class method returns a date / time formatting program initialized by default formatting. The formatted method can be modified using the ApplyPattern method as needed. SIMPLEDATEFORMAT function inheritance: java.lang.object | ---- java.text.format | ---- java.text.dateFormat | ---- java.text.SIMPLEDATEFORMAT below is a small example: import Java.text. *; import java.util.date;

/ ** SIMPLEDATEFORMAT function syntax: g age marker Y year M Month D day H in the morning or afternoon (1 ~ 12) h in the day (0 ~ 23) M points s second S millisecond E Week D During the year The first few days in the first month of the first month of the first month of the first week in the first month, the first day of the morning a month AM, in the afternoon, in the morning (1 ~ 24) k, in the morning or Afternoon (0 ~ 11) z time zone * / public class formatdatetime {

Public static void main (String [] args) {SimpleDateFormat Myfmt = new SimpleDateFormat ("YYY YYY MM Moon DD Day HH MM] SS Second"); SimpleDateFormat Myfmt1 = New SimpleDateFormat ("YY / mm / dd hh: mm") SimpleDateformat myfmt2 = new simpledateformat ("YYY-MM-DD HH: MM: SS"); // Is equivalent to now.tolocalestring () SimpleDateFormat myfmt3 = new SimpleDateFormat ("YYYY MM Month DD date HH MM points SS seconds E "); SimpleDateFormat myfmt4 = new SimpleDateFormat (" X-time Z time zone in the first day of the first week in the first year in the year "); Date Now = new date (); System.out.println; system.out.println; system.out.println (Myfmt2.Format (now)); System.out.Println (MyFMT3. Format (now); system.out.println; system.out.println (now.togmtstring ()); system.out.println; system.out. Println () (now.toString ());}} Effect: December 16, 2004 17:24 27 seconds 04/12-16 17: 24: 27 December 16, 2004 17:24 In the 351st week of Thursday, 27 seconds, the 3rd week of the 3rd week of January 3rd week 17 o'clock CST time zone 16 DEC 2004 09:24:27 GMT2004-12-16 17: 24: 27thu Dec 16 17:24:27 CST 2004 below is a javabean: public class formatdatetime {PUB lic static String toLongDateString (Date dt) {SimpleDateFormat myFmt = new SimpleDateFormat ( "dd day when HH yyyy, MM month mm ss a E"); return myFmt.format (dt);} public static String toShortDateString (Date dt) { SimpleDateFormat myFmt = new SimpleDateFormat ( "when yy, mM month dd day HH mm fraction"); return myFmt.format (dt);} public static String toLongTimeString (date dt) {SimpleDateFormat myFmt = new SimpleDateFormat ( "HH mm ss SSSS" Return myfmt.format (dt);} public static string toshorttimeString (date dt) {SimpleDateFormat Myfmt = new SimpleDateFormat ("YY / mm / dd hh: mm"); return myfmt.format (dt);} public static void Main (String [] args) {date now = new date ();

转载请注明原文地址:https://www.9cbs.com/read-32816.html

New Post(0)