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:Main.java

public static void main(String[] args) {
    DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss.SSS");

    long now = System.currentTimeMillis();

    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(now);/* w  ww  .ja  va  2 s.  c o  m*/

    System.out.println(now + " = " + formatter.format(calendar.getTime()));
}

From source file:Main.java

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

    long time = System.currentTimeMillis();
    FileTime fileTime = FileTime.fromMillis(time);
    Path path = Paths.get("C:/tutorial/Java/JavaFX", "Topic.txt");

    try {// w  ww .  j a  va 2 s  .  c o m
        Files.setLastModifiedTime(path, fileTime);
    } catch (IOException e) {
        System.err.println(e);
    }

}

From source file:Main.java

public static void main(String[] args) {
    long time = System.currentTimeMillis();
    Date d = new Date(time);
    Timestamp t = new Timestamp(time);
    t.setNanos(123456789);/* w ww .  j  a va 2 s .  c o m*/
    System.out.println(d);
    System.out.println(t);
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss'.'");
    NumberFormat nf = new DecimalFormat("000000000");
    System.out.println(df.format(t.getTime()) + nf.format(t.getNanos()));
}

From source file:MainClass.java

public static void main(String[] args) {

    //Format milliseconds in long
    System.out.println(//from www  .  j  a  v a  2 s . c  om
            "4) MMM dd yy HH:mm >>>" + DateFormatUtils.format(System.currentTimeMillis(), "MMM dd yy HH:mm"));

}

From source file:Main.java

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

    File file = new File("filename");

    long modifiedTime = file.lastModified();
    // 0L is returned if the file does not exist

    long newModifiedTime = System.currentTimeMillis();
    boolean success = file.setLastModified(newModifiedTime);
    if (!success) {
        // operation failed.
    }// w  w  w  .  j  a va2  s  . c o  m
}

From source file:VectorBenchmark1.java

public static void main(String[] args) {
    Vector v = new Vector();

    long start = System.currentTimeMillis();
    for (int i = 0; i < MaxSize; i++)
        v.add(new Integer(i));
    long end = System.currentTimeMillis();
    System.out.println("Allocating vector elements: " + (end - start) + " milliseconds");

    Integer[] integerArray = new Integer[1];
    start = System.currentTimeMillis();
    for (int i = 0; i < MaxSize; i++) {
        if (i >= integerArray.length) {
            Integer[] b = new Integer[i * 2];
            System.arraycopy(integerArray, 0, b, 0, integerArray.length);
            integerArray = b;/*from   w w  w  .j  av  a  2  s  .  com*/
        }
        integerArray[i] = new Integer(i);
    }
    end = System.currentTimeMillis();
    System.out.println("Allocating array elements:  " + (end - start) + " milliseconds");

    start = System.currentTimeMillis();
    for (int j = 0; j < NTRIES; j++)
        for (int i = 0; i < MaxSize; i++) {
            Integer r = (Integer) v.get(i);
            v.set(i, new Integer(r.intValue() + 1));
        }
    end = System.currentTimeMillis();
    System.out.println("Accessing vector elements:  " + (end - start) + " milliseconds");

    start = System.currentTimeMillis();
    for (int j = 0; j < NTRIES; j++)
        for (int i = 0; i < MaxSize; i++) {
            Integer r = integerArray[i];
            integerArray[i] = new Integer(r.intValue() + 1);
        }
    end = System.currentTimeMillis();
    System.out.println("Accessing array elements:   " + (end - start) + " milliseconds");
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    File fileToChange = new File("C:/myfile.txt");

    Date filetime = new Date(fileToChange.lastModified());
    System.out.println(filetime.toString());

    System.out.println(fileToChange.setLastModified(System.currentTimeMillis()));

    filetime = new Date(fileToChange.lastModified());
    System.out.println(filetime.toString());

}

From source file:Main.java

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

    Path path = Paths.get("C:/tutorial/Java/JavaFX", "Topic.txt");
    long time = System.currentTimeMillis();
    FileTime fileTime = FileTime.fromMillis(time);
    try {/*from ww  w.j  a  v  a  2  s.com*/
        Files.setAttribute(path, "basic:lastModifiedTime", fileTime, LinkOption.NOFOLLOW_LINKS);
        Files.setAttribute(path, "basic:creationTime", fileTime, LinkOption.NOFOLLOW_LINKS);
        Files.setAttribute(path, "basic:lastAccessTime", fileTime, LinkOption.NOFOLLOW_LINKS);
    } catch (IOException e) {
        System.err.println(e);
    }

}

From source file:Main.java

public static void main(String[] args) {

    Path path = Paths.get("C:/tutorial/Java/JavaFX", "Topic.txt");

    long time = System.currentTimeMillis();
    FileTime fileTime = FileTime.fromMillis(time);
    try {// w  w  w .j a va  2  s  .c o  m
        BasicFileAttributeView bv = Files.getFileAttributeView(path, BasicFileAttributeView.class);
        bv.setTimes(fileTime, fileTime, fileTime);
    } catch (IOException e) {
        System.err.println(e);
    }

}

From source file:Main.java

public static void main(String[] args) {
    List<Trade> trades = TradeUtil.createTrades(100);

    int cpus = Runtime.getRuntime().availableProcessors();
    long start = System.currentTimeMillis();
    trades.stream().parallel().forEach(t -> doSomething(t));
    long end = System.currentTimeMillis();

    System.out.println("Time for parallel op:" + (end - start) / 1000 + "sec on " + cpus);
}