Date of Java

xiaoxiao2021-03-05  20

Date of Java

1. The title is not written, you will know after running.

import java.util.Date; import java.text.SimpleDateFormat; public class Demo {public static void main (String [] args) {Date now = new Date (); SimpleDateFormat f = new SimpleDateFormat ( "Today is" "yyyy Year MM DD Day E KK Point MM Division "); system.out.println (f.Format (now)); f = new simpledateformat (" A hh point mm ss second "); system.out.println (f .format (now);}}

You can think about it first before running, see if you think is the same.

2. Conversion from strings to date types:

import java.util.Date; import java.text.SimpleDateFormat; import java.util.GregorianCalendar; import java.text *;. public class Demo {public static void main (String [] args) {String strDate = "2005-04 "22nd";

// Note: The style of SimpleDateFormat constructor with strdate's style must match SimpleDateFormat SimpleDateFormat = New SimpleDateFormat ("YYYY MM Moon DD Day);

/ / Must capture exception Try {date Date = SimpleDateFormat.Parse (strdate); system.out.println (date);} catch (parseException px) {px.printstacktrace ();}}}

3. Transform milliseconds into a date type:

import java.util.Date; import java.text.SimpleDateFormat; import java.util.GregorianCalendar; import java.text *;. public class Demo {public static void main (String [] args) {long now = System.currentTimeMillis ( ); System.out.println ("Count:" now); Date DNOW = New Date (NOW); System.out.Println ("Date Type: DNOW);}}

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

New Post(0)