Use Java programming to print out the current moment of yesterday

Source: Internet
Author: User
Tags date1

Method One:

Import Java.util.Calendar;
public class test{
public static void Main (string[] args) {
Calendar cal = Calendar.getinstance ();
Cal.add (Calendar.date,-1);
System.out.println (Cal.gettime ());
}
}

Method Two:

Import Java.util.Calendar;
public class Test {
public static void Main (string[] args) {
Calendar C = calendar.getinstance ();
int Year=c.get (calendar.year);
int Month=c.get (calendar.month) +1; The system is 0 months from the beginning, and by December it will be zero. So when you take the month alone, you'll need to add one back to get the current month.
int Date=c.get (calendar.date);
int Hour=c.get (calendar.hour);
int Sencond=c.get (Calendar.second);
int Minute=c.get (calendar.minute);
System.out.println ("Today is" + "" +year+ "Year" +month+ "month" +date+ "Day" + "" +hour+ "Hour" +sencond+ "" "+minute+" seconds ");
int date1=date-1;
System.out.println ("Yesterday is" + "" +year+ "Year" +month+ "month" +date1+ "Day" + "" +hour+ "Hours" +sencond+ "" "+minute+" "Seconds");
}}

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.