Example usage for java.lang System currentTimeMillis

List of usage examples for java.lang System currentTimeMillis

Introduction

In this page you can find the example usage for java.lang System currentTimeMillis.

Prototype

@HotSpotIntrinsicCandidate
public static native long currentTimeMillis();

Source Link

Document

Returns the current time in milliseconds.

Usage

From source file:PendingInterrupt.java

public static void main(String[] args) {
    Thread.currentThread().interrupt();

    long startTime = System.currentTimeMillis();
    try {/*from w w  w  .  jav  a  2s. c o  m*/
        Thread.sleep(2000);
        System.out.println("NOT interrupted");
    } catch (InterruptedException x) {
        System.out.println("Interrupted");
    }

    System.out.println("elapsedTime=" + (System.currentTimeMillis() - startTime));
}

From source file:Elapsed.java

public static void main(String args[]) {
    long start, end;

    System.out.println("Timing a for loop from 0 to 1,000,000");

    start = System.currentTimeMillis(); // get starting time
    for (int i = 0; i < 1000000; i++)
        ;//from  w w  w .  j  a  v a  2  s . c  om
    end = System.currentTimeMillis(); // get ending time

    System.out.println("Elapsed time: " + (end - start));
}

From source file:Main.java

public static void main(String[] args) throws Exception {

    long time = System.currentTimeMillis();
    FileTime fileTime = FileTime.from(time, TimeUnit.MILLISECONDS);
    System.out.println(fileTime);

}

From source file:Main.java

public static void main(String[] args) throws Exception {

    long time = System.currentTimeMillis();
    FileTime fileTime = FileTime.fromMillis(time);
    System.out.println(fileTime.to(TimeUnit.HOURS));

}

From source file:Main.java

public static void main(String[] args) throws Exception {

    long time = System.currentTimeMillis();
    FileTime fileTime = FileTime.fromMillis(time);

    FileTime fileTime1 = FileTime.from(time, TimeUnit.MILLISECONDS);

    System.out.println(fileTime.compareTo(fileTime1));

}

From source file:Main.java

public static void main(String[] args) throws Exception {

    long time = System.currentTimeMillis();
    FileTime fileTime = FileTime.fromMillis(time);

    FileTime fileTime1 = FileTime.from(time, TimeUnit.MILLISECONDS);

    System.out.println(fileTime.equals(fileTime1));

}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    Date timeToRun = new Date(System.currentTimeMillis() + numberOfMillisecondsInTheFuture);
    Timer timer = new Timer();

    timer.schedule(new TimerTask() {
        public void run() {
            System.out.println("doing");
        }//from   www.  ja v a2 s .  c om
    }, timeToRun);
}

From source file:Main.java

public static void main(String[] args) {
    Timestamp timestamp = new Timestamp(System.currentTimeMillis());
    Date date = new Date(timestamp.getTime());

    // S is the millisecond
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM/dd/yyyy' 'HH:mm:ss:S");

    System.out.println(simpleDateFormat.format(timestamp));
    System.out.println(simpleDateFormat.format(date));
}

From source file:FloatDoubleTime.java

public static void main(String[] args) {
    long t0 = System.currentTimeMillis();
    float f = 0;/*from  ww  w.  j  a v a 2 s  .  c  o  m*/
    for (int i = 0; i < HOW_MANY; i++)
        f *= i;
    long t1 = System.currentTimeMillis();

    double d = 0;
    for (int i = 0; i < HOW_MANY; i++)
        d *= i;
    long t2 = System.currentTimeMillis();

    System.out.println("Float:  " + (t1 - t0) + " " + f);

    System.out.println("Double: " + (t2 - t1) + " " + d);
}

From source file:Main.java

public static void main(String[] args) {
    System.out.println(getDateTimeFromTimestamp(System.currentTimeMillis()));
    System.out.println(getDateFromTimestamp(System.currentTimeMillis()));
}