Example usage for java.util Date Date

List of usage examples for java.util Date Date

Introduction

In this page you can find the example usage for java.util Date Date.

Prototype

@Deprecated
public Date(String s) 

Source Link

Document

Allocates a Date object and initializes it so that it represents the date and time indicated by the string s , which is interpreted as if by the Date#parse method.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    long yourmilliseconds = 1119193123;
    SimpleDateFormat sdf = new SimpleDateFormat("MMM dd,yyyy HH:mm:ss.SSS");

    Date resultdate = new Date(yourmilliseconds);
    System.out.println(sdf.format(resultdate));
}

From source file:Main.java

public static void main(String[] argv) {
    System.out.println(getDatesFrom(new Date(1462312311223L)));
}

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);//from  w  ww  .j a  v a 2s .  c om
    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:Main.java

public static void main(String[] args) throws Throwable {
    SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss");
    Date date1 = format.parse("08:00:01");
    Date date2 = format.parse("23:00:05");
    Date date = new Date(date2.getTime() - date1.getTime());
    System.out.println(format.format(date));
}

From source file:MainClass.java

public static void main(String[] args) {
    try {// w  w w . j av  a2s .  c om
        URLConnection uc = new URL("http://www.demo2s.com").openConnection();
        System.out
                .println("Will retrieve file if it's been modified since " + new Date(uc.getIfModifiedSince()));
        uc.setIfModifiedSince(System.currentTimeMillis());
        System.out
                .println("Will retrieve file if it's been modified since " + new Date(uc.getIfModifiedSince()));
    } catch (Exception e) {
        System.err.println(e);
    }
}

From source file:MainClass.java

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

    URL u = new URL("http://www.java2s.com");
    HttpURLConnection http = (HttpURLConnection) u.openConnection();
    http.setRequestMethod("HEAD");
    System.out.println(u + "was last modified at " + new Date(http.getLastModified()));
}

From source file:Main.java

public static void main(String[] args) {

    File f = new File("c:/test.txt");

    boolean bool = f.exists();

    // if path exists
    if (bool) {/* www .j  a va 2  s  . c om*/
        // returns the time file was last modified
        long millisec = f.lastModified();

        // date and time
        Date dt = new Date(millisec);

        // path
        String path = f.getPath();

        System.out.print(path + " last modified at: " + dt);
    }

}

From source file:Main.java

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

    URL u = new URL("http://www.java2s.com");
    URLConnection uc = u.openConnection();
    System.out.println("Content-type: " + uc.getContentType());
    System.out.println("Content-encoding: " + uc.getContentEncoding());
    System.out.println("Date: " + new Date(uc.getDate()));
    System.out.println("Last modified: " + new Date(uc.getLastModified()));
    System.out.println("Expiration date: " + new Date(uc.getExpiration()));
    System.out.println("Content-length: " + uc.getContentLength());
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    SimpleDateFormat broken = new SimpleDateFormat("kk:mm:ss");
    broken.setTimeZone(TimeZone.getTimeZone("Etc/UTC"));
    SimpleDateFormat working = new SimpleDateFormat("HH:mm:ss");
    working.setTimeZone(TimeZone.getTimeZone("Etc/UTC"));

    Date epoch = new Date(0);

    System.out.println(broken.format(epoch));
    System.out.println(working.format(epoch));
}

From source file:Main.java

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

    URL u = new URL("http://www.java2s.com");
    URLConnection uc = u.openConnection();
    uc.connect();//from w  ww.  j  a  v  a 2 s  . c om
    System.out.println("Content-type: " + uc.getContentType());
    System.out.println("Content-encoding: " + uc.getContentEncoding());
    System.out.println("Date: " + new Date(uc.getDate()));
    System.out.println("Last modified: " + new Date(uc.getLastModified()));
    System.out.println("Expiration date: " + new Date(uc.getExpiration()));
    System.out.println("Content-length: " + uc.getContentLength());
}