Example usage for java.util GregorianCalendar setTime

List of usage examples for java.util GregorianCalendar setTime

Introduction

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

Prototype

public final void setTime(Date date) 

Source Link

Document

Sets this Calendar's time with the given Date.

Usage

From source file:com.microsoftopentechnologies.windowsazurestorage.WAStorageClient.java

public static SharedAccessBlobPolicy generatePolicy() {
    SharedAccessBlobPolicy policy = new SharedAccessBlobPolicy();
    GregorianCalendar calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
    calendar.setTime(new Date());

    calendar.add(Calendar.HOUR, 1);
    policy.setSharedAccessExpiryTime(calendar.getTime());
    policy.setPermissions(EnumSet.of(SharedAccessBlobPermissions.READ));

    return policy;
}

From source file:org.squale.welcom.outils.DateUtil.java

/**
 * retourne le porchain jour de la semaine saisi en paramtre par rapport  la date d'entre
 * //from  w  w  w.  ja  va 2 s . com
 * @param date date d'entre
 * @param dayofweek Jour de la semaine  utiliser
 * @return la date du prochain jour de la semaine
 */
public static java.util.Date getNext(final java.util.Date date, final int dayofweek) {
    final GregorianCalendar gc = new GregorianCalendar();
    gc.setTime(date);

    final int actualday = gc.get(Calendar.DAY_OF_WEEK);
    gc.add(Calendar.DATE, ((dayofweek - actualday + WEEK_DAYS) % WEEK_DAYS));

    return gc.getTime();
}

From source file:org.squale.welcom.outils.DateUtil.java

/**
 * Ajoute un certain nombre de jour  une date
 * /*from  w  ww . j  a v  a 2s  .co m*/
 * @param date1 Date sous forme de jave.util.Date
 * @param nbdays nombre de jours  ajouter
 * @return la date avec le nombre de jour ajout
 */
public static java.util.Date addDaysDate(final java.util.Date date1, final int nbdays) {
    if (date1 == null) {
        return null;
    }

    final GregorianCalendar cal = new GregorianCalendar();
    cal.setTime(date1);
    cal.add(Calendar.DATE, nbdays);

    return cal.getTime();
}

From source file:org.squale.welcom.outils.DateUtil.java

/**
 * @param day = jour  tester au format Date
 * @return Retourne si la date passe en entre correspond  un jour feri
 *//* w w  w  .  j  a  v  a 2s. c o m*/
public static boolean isPublicHolyday(final Date day) {
    if (day == null) {
        return false;
    }

    final GregorianCalendar gc = new GregorianCalendar();
    gc.setTime(day);

    final ArrayList ph = getPublicHolydays(gc.get(Calendar.YEAR));

    for (final Iterator iter = ph.iterator(); iter.hasNext();) {
        final Date d = (Date) iter.next();

        if (d.equals(day)) {
            return true;
        }
    }

    return false;
}

From source file:org.squale.welcom.outils.DateUtil.java

/**
 * Retourn l'anne en int d'une date//from   ww w.  j av  a2 s .  co  m
 * 
 * @param gc gregorien calendar
 * @param date date
 * @return l'anne en int d'une date
 */
private static int getYearOfDate(GregorianCalendar gc, final Date date) {

    // recupere l'anne de debut
    gc.setTime(date);
    return gc.get(Calendar.YEAR);
}

From source file:org.squale.welcom.outils.DateUtil.java

/**
 * @param dateDebut : date de dbut (java.util.Date)
 * @param dateFin : date de fin (java.util.Date)
 * @param unit : unit de temps dans laquelle doit tre calcule la dure (MILLI_SEC,SEC,DAY,HOUR,MIN)
 * @return retourne le nombre de jour entre deux dates les samedi et dimanche n'tant pas inclu
 *///w w w  .  j  a  v  a 2  s  . c o  m
public static long durationNoWeekEnd(final java.util.Date dateDebut, final java.util.Date dateFin,
        final long unit) {
    long duration = duration(dateDebut, dateFin, unit);
    final GregorianCalendar gc = new GregorianCalendar();

    if (duration != 0) {
        gc.setTime(dateDebut);

        while (gc.getTime().getTime() <= dateFin.getTime()) {
            if ((gc.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY)
                    || (gc.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY)) {
                duration--;
            }

            gc.add(Calendar.DATE, 1);
        }
    }

    return duration;
}

From source file:org.jamwiki.parser.image.ImageUtil.java

/**
 * Given a filename, generate the URL to use to store the file on the filesystem.
 *//*  www  .j a v  a 2 s  .c o  m*/
public static String generateFileUrl(String virtualWiki, String filename, Date date) throws WikiException {
    if (StringUtils.isBlank(virtualWiki)) {
        throw new WikiException(new WikiMessage("common.exception.novirtualwiki"));
    }
    String url = filename;
    if (StringUtils.isBlank(url)) {
        throw new WikiException(new WikiMessage("upload.error.filename"));
    }
    // file is appended with a timestamp of DDHHMMSS
    GregorianCalendar cal = new GregorianCalendar();
    if (date != null) {
        cal.setTime(date);
    }
    String day = Integer.toString(cal.get(Calendar.DAY_OF_MONTH));
    if (day.length() == 1) {
        day = "0" + day;
    }
    String hour = Integer.toString(cal.get(Calendar.HOUR_OF_DAY));
    if (hour.length() == 1) {
        hour = "0" + hour;
    }
    String minute = Integer.toString(cal.get(Calendar.MINUTE));
    if (minute.length() == 1) {
        minute = "0" + minute;
    }
    String second = Integer.toString(cal.get(Calendar.SECOND));
    if (second.length() == 1) {
        second = "0" + second;
    }
    String suffix = "-" + day + hour + minute + second;
    int pos = url.lastIndexOf('.');
    url = (pos == -1) ? url + suffix : url.substring(0, pos) + suffix + url.substring(pos);
    // now pre-pend the file system directory
    // subdirectory is composed of vwiki/year/month
    String year = Integer.toString(cal.get(Calendar.YEAR));
    String month = Integer.toString(cal.get(Calendar.MONTH) + 1);
    String subdirectory = "/" + virtualWiki + "/" + year + "/" + month;
    if (isImagesOnFS()) {
        File directory = ImageUtil.buildAbsoluteFile(subdirectory);
        if (!directory.exists() && !directory.mkdirs()) {
            throw new WikiException(
                    new WikiMessage("upload.error.directorycreate", directory.getAbsolutePath()));
        }
    }
    return subdirectory + "/" + url;
}

From source file:com.sammyun.util.DateUtil.java

/**
 * ??//from www .j  a v  a 2 s  .c  o  m
 * 
 * @param inDate 
 * @param days ?
 * @return Date
 */
public static Date getDateByAddDays(Date inDate, int days) {
    GregorianCalendar calendar = new GregorianCalendar();
    calendar.setTime(inDate);
    calendar.add(Calendar.DATE, days);
    return calendar.getTime();
}

From source file:com.sammyun.util.DateUtil.java

/**
 * ??//  ww  w.ja  va 2 s.  c  om
 * 
 * @param inDate 
 * @param days ?
 * @return Date
 */
public static Date getDateByAddMonth(Date inDate, int month) {
    GregorianCalendar calendar = new GregorianCalendar();
    calendar.setTime(inDate);
    calendar.add(Calendar.MONTH, month);
    return calendar.getTime();
}

From source file:eu.europa.esig.dss.DSSXMLUtils.java

/**
 * Converts a given {@code Date} to a new {@code XMLGregorianCalendar}.
 *
 * @param date the date to be converted// ww w. ja v  a 2s.c o  m
 * @return the new {@code XMLGregorianCalendar} or null
 */
public static XMLGregorianCalendar createXMLGregorianCalendar(final Date date) {

    if (date == null) {
        return null;
    }
    final GregorianCalendar calendar = new GregorianCalendar();
    calendar.setTime(date);
    try {

        XMLGregorianCalendar xmlGregorianCalendar = DatatypeFactory.newInstance()
                .newXMLGregorianCalendar(calendar);
        xmlGregorianCalendar.setFractionalSecond(null);
        xmlGregorianCalendar = xmlGregorianCalendar.normalize(); // to UTC = Zulu
        return xmlGregorianCalendar;
    } catch (DatatypeConfigurationException e) {
        LOG.warn("Unable to properly convert a Date to an XMLGregorianCalendar " + e.getMessage(), e);
    }
    return null;
}