Example usage for java.util Calendar getTimeInMillis

List of usage examples for java.util Calendar getTimeInMillis

Introduction

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

Prototype

public long getTimeInMillis() 

Source Link

Document

Returns this Calendar's time value in milliseconds.

Usage

From source file:Main.java

public static void main(String[] args) {
    Calendar now = Calendar.getInstance();
    System.out.println("Current milliseconds since Jan 1, 1970 are :" + now.getTimeInMillis());

}

From source file:Main.java

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

    Calendar cal = Calendar.getInstance();

    // print current time in milliseconds
    System.out.println("Current time is : " + cal.getTimeInMillis());

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Calendar local = Calendar.getInstance();
    Calendar japanCal = new GregorianCalendar(TimeZone.getTimeZone("Japan"));
    japanCal.setTimeInMillis(local.getTimeInMillis());
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Calendar local = Calendar.getInstance();
    Calendar japanCal = new GregorianCalendar(TimeZone.getTimeZone("Japan"));
    japanCal.setTimeInMillis(local.getTimeInMillis());

    int hour = japanCal.get(Calendar.HOUR); // 3
    int minutes = japanCal.get(Calendar.MINUTE); // 0
    int seconds = japanCal.get(Calendar.SECOND); // 0
    boolean am = japanCal.get(Calendar.AM_PM) == Calendar.AM; // true
}

From source file:MainClass.java

public static void main(String[] args) {

    Calendar calendar = new GregorianCalendar(2000, // year
            10, // month
            1); // day of month
    java.sql.Date date = new java.sql.Date(calendar.getTimeInMillis());

}

From source file:Main.java

public static void main(String args[]) {
    Calendar cal1 = Calendar.getInstance();
    Calendar cal2 = Calendar.getInstance();
    cal2.add(Calendar.HOUR, 2);//  ww w .  jav a2  s  . c o m
    cal2.add(Calendar.MINUTE, 42);
    cal2.add(Calendar.SECOND, 12);
    long secs = (cal2.getTimeInMillis() - cal1.getTimeInMillis()) / 1000;
    String display = String.format("%02d:%02d:%02d", secs / 3600, (secs % 3600) / 60, (secs % 60));
    System.out.println(display);

}

From source file:Main.java

public static void main(String[] args) {
    Date date1 = new Date(2009, 01, 10);
    Date date2 = new Date(2015, 07, 01);
    Calendar calendar1 = Calendar.getInstance();
    Calendar calendar2 = Calendar.getInstance();
    calendar1.setTime(date1);//  ww  w . j a  va 2  s  .  c  om
    calendar2.setTime(date2);
    long milliseconds1 = calendar1.getTimeInMillis();
    long milliseconds2 = calendar2.getTimeInMillis();
    long diff = milliseconds2 - milliseconds1;
    long diffSeconds = diff / 1000;
    long diffMinutes = diff / (60 * 1000);
    long diffHours = diff / (60 * 60 * 1000);
    long diffDays = diff / (24 * 60 * 60 * 1000);
    System.out.println("\nThe Date Different Example");
    System.out.println("Time in milliseconds: " + diff + " milliseconds.");
    System.out.println("Time in seconds: " + diffSeconds + " seconds.");
    System.out.println("Time in minutes: " + diffMinutes + " minutes.");
    System.out.println("Time in hours: " + diffHours + " hours.");
    System.out.println("Time in days: " + diffDays + " days.");
}

From source file:Main.java

public static void main(String[] args) {
    Calendar calendar1 = Calendar.getInstance();
    Calendar calendar2 = Calendar.getInstance();
    calendar1.set(2015, 01, 10);/*from   w w  w. j  a v a 2 s . c  o  m*/
    calendar2.set(2015, 07, 01);
    long milliseconds1 = calendar1.getTimeInMillis();
    long milliseconds2 = calendar2.getTimeInMillis();
    long diff = milliseconds2 - milliseconds1;
    long diffSeconds = diff / 1000;
    long diffMinutes = diff / (60 * 1000);
    long diffHours = diff / (60 * 60 * 1000);
    long diffDays = diff / (24 * 60 * 60 * 1000);
    System.out.println("\nThe Date Different Example");
    System.out.println("Time in milliseconds: " + diff + " milliseconds.");
    System.out.println("Time in seconds: " + diffSeconds + " seconds.");
    System.out.println("Time in minutes: " + diffMinutes + " minutes.");
    System.out.println("Time in hours: " + diffHours + " hours.");
    System.out.println("Time in days: " + diffDays + " days.");
}

From source file:Main.java

public static void main(String[] args) {
    int year = 2009;
    int month = 0; // January
    int date = 1;

    Calendar cal = Calendar.getInstance();
    cal.clear();/*from  w  ww. j  av  a  2s  .c  o  m*/

    cal.set(Calendar.YEAR, year);
    cal.set(Calendar.MONTH, month);
    cal.set(Calendar.DATE, date);

    java.sql.Date sqlDate = new java.sql.Date(cal.getTimeInMillis());
    System.out.println(sqlDate);
}

From source file:Main.java

public static void main(String[] args) {

    Calendar today = new GregorianCalendar();
    Calendar purchased = new GregorianCalendar();

    purchased.add(Calendar.DAY_OF_MONTH, 1);

    Calendar lastActDate = new GregorianCalendar();
    lastActDate.setTimeInMillis(today.getTimeInMillis() - purchased.getTimeInMillis());
}