Date ()),/or use YYYY/MM/DD as Formatdateformat df2 = new SimpleDateFormat ("yyyy/m M/dd "); String FormattedDate2 = Df2.format (thedate); 3. Working with Dates and Calendars3.1. CalendarThe java.util.Calendar class is an abstract encapsulation of the Date object.Calendar provides getter and setter for the date fields.Public final int Get (int. field) public final void set (int field, int value) Table 1. Calendar field Access Tip the Calendar.
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 application.
Conversion between date objects and millisecond values.
Millisecond value-> Date object: 1.new Date (TimeMillis); 2. setTime ()
Therefore, you can use the Date object method to operate a certain year, month,
;
}
}
What kind of pits are there?
Where is the pit:
One of the things that I've contacted before involves moving some data to another collection in the MongoDB database 00:00:00 every day--a table in a relational database. This collection name is a fixed name plus the year and month in which the current two month ago dates.
This feature was there before I touched the project, which was implemented by my colleagues and wrote a Java timed task.
(Calendar.minute); theSystem.out.println ("MINUTE-30 =" +MINUTE); the - //formatted display instr = (NewSimpleDateFormat ("Yyyy-mm-dd HH:mm:ss:SS") . Format (Calendar.gettime ()); the System.out.println (str); the About //Reset Calendar Show Current Time theCalendar.settime (NewDate ()); thestr = (NewSimpleDateFormat ("Yyyy-mm-dd HH:mm:ss:SS") . Format (Calendar.gettime ()); the System.out.println (str); + - //
[Common Java class libraries] _ date operation class (date, calendar AR) Notes
Objectives of this chapter:
Understanding how to use the date classYou can use the calendar class to obtain the complete date:
The date class is a commonly used class, but its operation date format does not meet the individual's needs. If you want to further obtain the time you need, y
First, Java.util.Date date classPrivate Integer age;//Employee agePrivate String hiredate;//Entry timeThe basic information about the employee is stored in the system, including the age of the employee, and it is unreasonable to use the Integer/int type to indicate the age.Do you have to change the age of the employees in the system by 1 each year?1. Class Date represents a specific moment, accurate to milliseconds. There is a method in the date class that returns the millisecond value since 197
Java. util. Date: indicates a specific moment, accurate to milliseconds. Before jdk1.1, the date is interpreted as the year, month, day, hour, minute, and second values, but its functions are not easy to internationalize. Therefore, from jdk1.1, use the calendar class to convert the date and time fields, and use the dateformat class to format and parse the date string. Void settime (Long Time): sets this da
but show out, certainly with Simpledateformart, mode for YYYY-MM-DD HH:mm:ss EE4. Set the valueCal.set (2013, 5, 4, 13, 44, 51);//Date and time (month 0 stands for January)Cal.set (Calendar.year, 2014);//yearCal.set (Calendar.month, 7);//month (month 0 stands for January)Cal.set (Calendar.date, 11);//dayCal.set (Calendar.hour_of_day, 15);//Cal.set (Calendar.minute, 33);//minCal.set (Calendar.second, 32);//sec5. Operation ValueCal.add (calendar.year, 1);//yearCal.add (Calendar.month, 1);//monthC
This article describes the date-related operations in the Java development process, sharing the following code:
Package JSE;
Import java.io.UnsupportedEncodingException;
Import java.text.ParseException;
Import Java.text.SimpleDateFormat;
Import Java.util.Calendar;
Import Java.util.Date;
Import Java.util.Locale; /** * Common Date Operation * * @author Puck * createdate 2015-07-30 22:54:38/public class TestDate {public static void main ( String
Objective
What exactly is a Calendar? Chinese translation is the calendar, then we can immediately think of our lives in the Yang (public) calendar, Yin (Nong) calendar points. What is the difference between them?
For example, there are:
Definition of month-yang ' (gong) calenda
ListThe next step is to get the date from the database, to render it on the interface, and in the controller We convert the date in the database to the JSON to the foreground, about the JSON The conversion, you can see the previous blog "Java SSH project summary--jqueryligerui-form JSON conversion ",controller Code,/** get the Set date record for the last month or next January, upload the page to render the cal
" + Days + "); + } - the //Set DateBayi @Test the Public voidtest4 () { theCalendar.set (Calendar.year, 2000); -System.out.println ("Now is" + calendar.get (calendar.year) + "year"); - theCalendar.set (2008, 8, 8); the //Get year the intYear =Calendar.get (calendar.year); the - //Get Month the intmonth =Calendar.get (calendar.month); the the //Get Day94 intDay =Calendar.get (calendar.day_of_month); the theSystem.out.println ("Now
Java SSH Project Summary-set the calendar of work days
Preface
The topic of today's article is calendar. First, we will introduce the background. This calendar serves as an online booking system. Online Booking means selecting workdays and then making an appointment for specific services, the workday settings are com
1.java.util.calendar
The Calendar class is an abstract class that provides methods for a specific moment to transform between a set of calendar fields such as year, MONTH, Day_of_month, HOUR, and for manipulating calendar fields, such as getting the date of next week. Instantly available in milliseconds, it is an offset from the 00:00:00.000 (i.e. Greenwich Mean
convert a string type to a date type//you need to create an object to receive the converted objectSystem.out.println ("string converted to date,d2=" +D2); //Date converted to StringString s1=Sdf1.format (D2); System.out.println ("Date is converted to string type, s1=" +S1); }}Importjava.text.ParseException;ImportJava.text.SimpleDateFormat;ImportJava.util.Calendar;Importjava.util.Date;ImportJava.util.GregorianCalendar; Public classDemo03 { Public Stat
Package zhangxuan.test01;Import Java.text.DateFormat;Import java.text.ParseException;Import Java.text.SimpleDateFormat;Import Java.util.Calendar;Import Java.util.Date;Import Java.util.GregorianCalendar;Import Java.util.Scanner;public class Lianxi06 { public static void Main (string[] args) { System.out.println ("Please enter a date (by format: 2030-3-10):");//output a prompt command Scanner Scanner = new Scanner (system.in);//Use the scanner class to implement keyboard input (honestly, this thi
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.