JAVA 46th-Other Object API (2) Date Class amp; Calendar class (key points)
Date class (important)
During development, time is often displayed, so you must be familiar with the Date app
Package com.java.mvc.util;
Import Java.text.DateFormat;Import java.text.ParseException;Import Java.text.SimpleDateFormat;Import java.util.ArrayList;Import Java.util.Calendar;Import Java.util.Date;Import Java.util.GregorianCalendar;Import java.util.List;
public class Dateutils {
Public final static String format_yyyy_mm_dd = "YYYY-MM-DD";
Public final static String format_yyyy_mm_dd_hh_mm_ss = "Yyyy-mm-dd hh:mm:ss";
Public final static String FORMAT_
Date class:1Date Date =NewDate ();//gets the current system time2System.out.println ("Year:" +date.getyear ());3 4Calendar calendar = Calendar.getinstance ();//gets the current system time. 5System.out.println ("Year:" +Calendar.get (calendar.year));6System.out.println ("Month:" + (Calendar.get (calendar.month) +1));7System.out.println ("Day:" +Calendar.g
= new Date ();Note: This place da.gettime () Gets the value of a long typeSystem.out.println (Da.gettime ());Converted from date to timestampFirst method: Use new Timestamp (long)Timestamp t = new Timestamp (new Date (). GetTime ());System.out.println (t);Second method: use timestamp (int year,int month,int date,int h
1. When working with the Oracle database using JDBC, the date type of the database that corresponds to the java.sql.Date type is used, which can be saved and read only at this time.Time (hours, minutes, seconds) can not be read and saved;The query result set can get data of the Date type directly: Java.sql.Date date=resultset.getdate ("DateTime");Data of the Java
Original: Java High imitation Weibo date display format, Date helper classSource code: Http://www.zuidaima.com/share/1550463377902592.htmImitation Sina Weibo date formatting tool class:For example:1. Just2. XX minutes ago3. HH hours ago4. Today hh:mm5. Yesterday hh:mm6. The day before hh:mm7. Last month YYYY-MM-DD hh:m
JAVA 46th-Other Object API (2) Date Class Calendar class (important), apidate
Date class (important)
During development, time is often displayed, so you must be familiar with the Date
four formats of Short,medium,long,fullSystem.out.println ("Date:" +df3.format (date));//Convert a string to date + time format, format fixedDateFormat DF4 =NULL; DF4= Dateformat.getdatetimeinstance (Dateformat.full,dateformat.full,NewLocale ("zh", "CN")); System.out.println ("DateTime:" +df4.format (date));//Convert a
=NewSimpleDateFormat ();//Create date format class object toSystem.out.println (Sdf.format (d));//format a string date 17-6-6 pm 1:17 + } - the}1 /*2 * Get the current time how many days you were born3 * 1. Put the current date and your birthday in string type first4 * 2. Format the two string as a
Overview and methods of the date class are used* Overview of the A:date class* Class Date represents a specific moment, accurate to milliseconds.* B: Construction method* Public Date ()* Public
date, int hourofday, int minute)
Public final void set(int year, int month, int date, int hourofday, int minute, int second)
/** * Gets the number of days of February for any year * * Analysis: * A: Keyboard input any year * B: Set calendar Month Day * C: Set months: 2 * days: 1 (actually March 1) * D: Push the time forward one day * E: Output
Date classDate: The class date represents a specific moment, accurate to milliseconds. Construction Method:Date (): The default is to get the current date timeDate (long date): Sets the current date according to the specified mi
Date, time, and date classes, which are described in the util package instead of in the SQL packageDate: Represents a specific time instantaneous, accurate to milliseconds (1000 milliseconds = 1 seconds)Time and date operations are based on millisecond valuesTime Origin:January 1, 1970, 0:0 0 seconds, corresponding millisecond value is 0Gets the millisecond value
1.Date class overviewClass date represents a specific moment, accurate to milliseconds2. Construction methodPublic Date ()Public date (long date)3. Member MethodsPublic long GetTime ()public void SetTime (long time)Packagecom;impo
2018-05-14Date ClassFirst, date classSpeaking of java.util.Date, classes Date represent specific moments, accurate to milliseconds.A large number of method reads in the date class are obsolete and obsolete does not mean that they do not exist and can still be used, but not recommended. We are officially advised to use
1. Overview of the Date classClass date represents a specific moment, accurate to milliseconds2. Construction method Public Date (): Creates a day object based on the current default millisecond value Public Date (long date): Creates a
Application of Calendar classThe most important role of the date class is to get the current time, while the class also has set time and some other functions, but because of its own design problems, these methods have been criticized many, not recommended, it is recommended to use the Calendar class for time and
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.