Example usage for java.util Calendar getTime

List of usage examples for java.util Calendar getTime

Introduction

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

Prototype

public final Date getTime() 

Source Link

Document

Returns a Date object representing this Calendar's time value (millisecond offset from the Epoch").

Usage

From source file:info.magnolia.cms.util.DateUtil.java

/**
 * Get the equivalent UTC calendar to a local calendar
 *//*from  www  .ja v  a  2  s  .co m*/
public static Calendar getLocalCalendarFromUTC(Calendar utc) {
    Date valueDate = utc.getTime();
    Calendar c = Calendar.getInstance(); // this has the default timezone for the server
    c.setTime(valueDate);
    return c;
}

From source file:Main.java

public static void showRounding(Calendar b) {
    System.out.println("-----------------------");
    System.out.println(b.getTime() + " is start point");
    System.out.println(toNextWholeHour(b).getTime() + " is next whole hour");
    System.out.println(toNextWholeMinute(b).getTime() + " is next whole minute");
    /*        System.out.println(toNearestWholeMinute(b).getTime() + " is nearest whole minute");
     System.out.println(toNearestWholeHour(b).getTime() + " is nearest whole hour");*/
}

From source file:Main.java

public static Date add(Date date, int field, int amount) {
    Calendar c = Calendar.getInstance();
    c.setTime(date);/* w  w  w.  j  a  va  2 s  .co m*/
    c.add(field, amount);
    return c.getTime();
}

From source file:Main.java

public static String getCurrentDate(String format) {
    String curDateTime = null;//from ww  w  . j  a v  a2  s . co m
    try {
        SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(format);
        Calendar c = new GregorianCalendar();
        curDateTime = mSimpleDateFormat.format(c.getTime());
    } catch (Exception e) {
        e.printStackTrace();
    }
    return curDateTime;

}

From source file:Main.java

public static Date addDay(Date date, int n) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);//from   w w w  .  j  ava 2  s  . com
    cal.add(Calendar.DATE, n);
    return cal.getTime();

}

From source file:Main.java

public static Date addFiveMinutes(Date date) {

    Calendar cal = Calendar.getInstance();
    cal.setTime(date);/* w w w. j  ava 2s . c  o m*/
    cal.add(Calendar.MINUTE, 5);
    return cal.getTime();
}

From source file:Main.java

public static Date addMonth(Date date, int n) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);/*from www  . jav a2s  .c om*/
    cal.add(Calendar.MONTH, n);
    return cal.getTime();

}

From source file:Main.java

public static String StampToyyyyMMdd(long stamp) {

    Date date = null;/*w w w  .  j  a v a  2  s .  c o m*/
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(stamp);
    date = calendar.getTime();

    String format = "yyyy-MM-dd";
    SimpleDateFormat sdf = new SimpleDateFormat(format);
    //sdf.setTimeZone(TimeZone.getTimeZone("UTC"));   
    sdf.setTimeZone(TimeZone.getTimeZone("PRC"));

    return sdf.format(date);

}

From source file:Main.java

public static String calendar2strDate(Calendar calendar, String pattern) {
    SimpleDateFormat sdf = new SimpleDateFormat(pattern);
    return sdf.format(calendar.getTime());
}

From source file:Main.java

public static String convertTime(int fetchDate, SimpleDateFormat sdf) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(new Date((long) fetchDate * 1000));
    return sdf.format(cal.getTime());
}