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

public static String getServerTime() {
    Calendar calendar = Calendar.getInstance();
    serverDateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
    return serverDateFormat.format(calendar.getTime());
}

From source file:Main.java

private static Date getStartWeekOfMonth(int year, int month) {
    Calendar c = Calendar.getInstance();
    c.set(year, month - 1, 1);//from w ww  .j a v  a  2s  .  c  o m
    int week = c.get(Calendar.DAY_OF_WEEK);
    return getDistanceDate(c.getTime(), 1 - week);
}

From source file:org.lieuofs.extraction.etatpays.ExtractionPays.java

private static List<EtatTerritoirePersistant> filtre(List<EtatTerritoirePersistant> listeOriginal) {
    List<EtatTerritoirePersistant> listeFiltree = new ArrayList<EtatTerritoirePersistant>();
    for (EtatTerritoirePersistant etatTerritoire : listeOriginal) {
        // On slectionne tous les tats territoire reconnu il ya moins de 2 ans
        Calendar cal = Calendar.getInstance();
        cal.roll(Calendar.YEAR, -5);
        Date ilYa5an = cal.getTime();
        Date dateReconnaissance = etatTerritoire.getDateReconnaissance();
        if (null != dateReconnaissance && dateReconnaissance.compareTo(ilYa5an) > 0) {
            listeFiltree.add(etatTerritoire);
        }/* w  ww .ja  v a2 s .  c o  m*/
    }
    return listeFiltree;
}

From source file:Main.java

public static Date startOfNextDay(Date origDate) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(origDate);/*www .  j  a v a2 s. c  om*/
    cal.add(Calendar.DATE, 1);

    return startOfDay(cal.getTime());
}

From source file:Main.java

public static Date addDays(Date date, int days) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);/*ww w . j av  a2  s . co m*/
    cal.add(Calendar.DATE, days); //minus number would decrement the days
    return cal.getTime();
}

From source file:Main.java

public static String longFormatTime(Calendar time) {
    SimpleDateFormat f = new SimpleDateFormat("EEE, MMM d, h:mm a");
    f.setCalendar(time);// w  w w .j  a  v  a 2s  . c  o m

    return f.format(time.getTime());
}

From source file:Main.java

/**
 * Return date in specified format./*from www . j  ava 2s  .  co  m*/
 * @param  milliSeconds Date in milliseconds
 * @param  dateFormat Date format 
 * @return String representing date in specified format
 */
public static String getDate(long milliSeconds, String dateFormat) {
    // Create a DateFormatter object for displaying date in specified format.
    DateFormat formatter = new SimpleDateFormat(dateFormat);
    // Create a calendar object that will convert the date and time value in milliseconds to date. 
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(milliSeconds);
    return formatter.format(calendar.getTime());
}

From source file:Main.java

/**
 * Check the schedule has expired or not
 * //from   w  ww. ja  v a2  s .com
 * @param endDate
 * @return
 */
public static boolean hasNotExpired(Date endDate) {
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.DAY_OF_MONTH, -1);

    // Check expired date
    return (endDate == null || cal.getTime().before(endDate));
}

From source file:Main.java

public static Date getTime(int year, int month, int day) {
    Calendar date = Calendar.getInstance();
    date.set(year, month, day, 0, 0, 0);
    date.set(Calendar.MILLISECOND, 0);
    return date.getTime();
}

From source file:Main.java

public static Date getDateDayBefore(Date originalDate, int days) {
    Calendar cal = new GregorianCalendar();
    cal.setTime(originalDate);/*from   ww  w .  j a  v  a 2s  .  c o m*/
    cal.add(Calendar.DAY_OF_MONTH, days * -1);
    return cal.getTime();
}