System.currenttimemillis () function in Java

Source: Internet
Author: User

System.currenttimemillis (): The number of milliseconds that can be extracted to the current time, producing a current millisecond, which is actually the number of milliseconds since 0 o'clock January 1, 1970.

Common role: Generally use 2 time difference to get run time, commonly used to compare the efficiency of 2 algorithms.

Long start = System.currenttimemillis ();


Here you can add the time you want to know how the method runs.

Long end = System.currenttimemillis ();

System.out.println ("Running Time:" + (End-start));

format system.currenttimemillis ()

1 Import Java.text.SimpleDateFormat;
2 Import Java.util.Locale;
3
4
5 public class Formatcurrenttime {
6/**
7 * @param args
8 */
9 public static void Main (string[] args) {
10
One simpledateformat SDF = new SimpleDateFormat ("", Locale.simplified_chinese);
Sdf.applypattern ("yyyy mm month DD Day hh when mm minute ss seconds");
System.out.println (Sdf.format (System.currenttimemillis ()));
14
15}
16}
17


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.