0-point and current time stamp of the day

Source: Internet
Author: User

Import Java.sql.Timestamp;
Import java.text.ParseException;
Import Java.text.SimpleDateFormat;
Import Java.util.Calendar;
Import Java.util.Date;
Import Java.util.GregorianCalendar;

public class Test {

Public Timestamp Getdaybegin () {
Calendar cal = Calendar.getinstance ();
Cal.set (calendar.hour_of_day, 0);
Cal.set (Calendar.second, 0);
Cal.set (calendar.minute, 0);
Cal.set (Calendar.millisecond, 001);
return new Timestamp (Cal.gettimeinmillis ());
}

 public Timestamp Getdaybegintimestamp () {
  date date = new Date ();
   GregorianCalendar gc = new GregorianCalendar ();
  gc.settime (date);
  date date2 = new Date (Date.gettime ()-Gc.get (GC. Hour_of_day) *
    * 1000-gc.get (GC. MINUTE) * 1000-gc.get (GC. SECOND)
    * 1000);
  return New Timestamp (Date2.gettime ());
 }

public static void Main (string[] args) throws ParseException {
Current 0-point time stamp
System.out.println (New Test (). Getdaybegin ());
0-point time stamp of the day
System.out.println (New Test (). Getdaybegintimestamp ());
Current time stamp
System.out.println (New SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"). SSS ")
. Format (New Date ());
System.out.println (Calendar.getinstance (). GetTime ());
Current time stamp
System.out.println (New Timestamp (System.currenttimemillis ()));

}

}

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.