String date format conversion

xiaoxiao2021-03-06  124

The API used is SimpleDateFormat, which is Java.Text.SIMPLEDATEFORMAT, so remember imported in IMPORT! Usage: SimpleDateFormat SDF = New SimpleDateFormat ("YYY-MM-DD HH: MM: SS"); this line is the most important, it establishes the format of the conversion, YYYY is a complete year year, MM is the month, DD is the date, as for HH: mm: SS does not need me to explain again! PS: Why do some formats uppercase, some formats lower-write, it is afraid to avoid confusion, such as mm is a month, mm is divided; HH is 24 hours, and HH is 12 small system 1. Date: 2002-10 -8 15:30:22 To turn it into the date, you can use Date Date = SDF.PARSE ("2002-10-8 15:30:22"); 2. Date turning string, if the date is turned to String available String DateStr = SDF.Format (New Date ()); This string is similar 2002-10-08 14:55:38 Through this api, we can transfer the date as we want. String format, for example, want to output the date to October 08, 2002, we can write: SimpleDateFormat SDF = New SimpleDateFormat ("YYY YYY MM Month Day"); string datestr = SDF.Format (new date () ); DateStr will output according to our format

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

New Post(0)