Example usage for java.util GregorianCalendar getTime

List of usage examples for java.util GregorianCalendar getTime

Introduction

In this page you can find the example usage for java.util GregorianCalendar 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:org.squale.welcom.outils.DateUtil.java

/**
 * Ajoute un certain nombre de jour  une date
 * /*  w w  w. j a v  a2  s . 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 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
 *//*ww  w.  j a  v  a  2s.co  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:com.prowidesoftware.swift.model.mx.BusinessHeader.java

/**
 * Returns a gregorian calendar for current moment in UTC time zone
 * @return created calendar or null if DatatypeFactory fails to create the calendar instance
 *//* w  ww .  j  a  v a2s.  c  o m*/
private static XMLGregorianCalendar now() {
    GregorianCalendar c = new GregorianCalendar();
    c.setTime(Calendar.getInstance(TimeZone.getTimeZone("UTC")).getTime());
    XMLGregorianCalendar creationDate = null;
    try {
        /*
         * important: cannot create XMLGregorianCalendar directly from Calendar object, 
         * specific format must be used for the unmarshalled XML to pass XSD validation.
         */
        creationDate = DatatypeFactory.newInstance()
                .newXMLGregorianCalendar(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").format(c.getTime()));
    } catch (DatatypeConfigurationException e) {
        log.log(Level.WARNING, "error initializing header creation date", e);
    }
    return creationDate;
}

From source file:org.apache.ranger.audit.provider.MiscUtil.java

public static Date getUTCDateForLocalDate(Date date) {
    TimeZone gmtTimeZone = TimeZone.getTimeZone("GMT+0");
    Calendar local = Calendar.getInstance();
    int offset = local.getTimeZone().getOffset(local.getTimeInMillis());
    GregorianCalendar utc = new GregorianCalendar(gmtTimeZone);
    utc.setTimeInMillis(date.getTime());
    utc.add(Calendar.MILLISECOND, -offset);
    return utc.getTime();
}

From source file:com.emcopentechnologies.viprcloudstorage.WAStorageClient.java

/**
 * Generates SAS URL for blob in Cloud storage account
 * @param storageAccountName/*from  www. j av  a2  s  .  c o  m*/
 * @param storageAccountKey
 * @param containerName
 * @param strBlobURL
 * @return SAS URL
 * @throws Exception
 */
public static String generateSASURL(String storageAccountName, String storageAccountKey, String containerName,
        String saBlobEndPoint) throws Exception {
    StorageCredentialsAccountAndKey credentials = new StorageCredentialsAccountAndKey(storageAccountName,
            storageAccountKey);
    URL blobURL = new URL(saBlobEndPoint);
    String saBlobURI = new StringBuilder().append(blobURL.getProtocol()).append("://")
            .append(storageAccountName).append(".").append(blobURL.getHost()).append("/").toString();
    CloudStorageAccount cloudStorageAccount = new CloudStorageAccount(credentials, new URI(saBlobURI),
            new URI(getCustomURI(storageAccountName, QUEUE, saBlobURI)),
            new URI(getCustomURI(storageAccountName, TABLE, saBlobURI)));
    // Create the blob client.
    CloudBlobClient blobClient = cloudStorageAccount.createCloudBlobClient();
    CloudBlobContainer container = blobClient.getContainerReference(containerName);

    // At this point need to throw an error back since container itself did not exist.
    if (!container.exists()) {
        throw new Exception("WAStorageClient: generateSASURL: Container " + containerName
                + " does not exist in storage account " + storageAccountName);
    }

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

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

    BlobContainerPermissions containerPermissions = new BlobContainerPermissions();
    containerPermissions.getSharedAccessPolicies().put("jenkins" + System.currentTimeMillis(), policy);
    container.uploadPermissions(containerPermissions);

    // Create a shared access signature for the container.
    String sas = container.generateSharedAccessSignature(policy, null);

    return sas;
}

From source file:org.apache.ranger.audit.provider.MiscUtil.java

public static Date getUTCDate() {
    TimeZone gmtTimeZone = TimeZone.getTimeZone("GMT+0");
    Calendar local = Calendar.getInstance();
    int offset = local.getTimeZone().getOffset(local.getTimeInMillis());
    GregorianCalendar utc = new GregorianCalendar(gmtTimeZone);
    utc.setTimeInMillis(local.getTimeInMillis());
    utc.add(Calendar.MILLISECOND, -offset);
    return utc.getTime();
}

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.etudes.jforum.view.forum.common.TopicsCommon.java

public static List prepareDiffTopics(List topics) throws Exception {
    UserSession userSession = SessionFacade.getUserSession();

    long lastVisit = userSession.getLastVisit().getTime();
    // int hotBegin = SystemGlobals.getIntValue(ConfigKeys.HOT_TOPIC_BEGIN);
    int hotBegin = SakaiSystemGlobals.getIntValue(ConfigKeys.HOT_TOPIC_BEGIN);

    // int postsPerPage = SystemGlobals.getIntValue(ConfigKeys.POST_PER_PAGE);
    int postsPerPage = SakaiSystemGlobals.getIntValue(ConfigKeys.POST_PER_PAGE);
    Map topicsTracking = (HashMap) SessionFacade.getAttribute(ConfigKeys.TOPICS_TRACKING);
    List newTopics = new ArrayList(topics.size());

    boolean checkUnread = (userSession.getUserId() != SystemGlobals.getIntValue(ConfigKeys.ANONYMOUS_USER_ID));

    List topicMarkTimes = null;//from  w  w  w. ja v a 2  s  . c  o m
    if (topics.size() > 0) {
        topicMarkTimes = DataAccessDriver.getInstance().newTopicMarkTimeDAO()
                .selectCourseTopicMarkTimes(userSession.getUserId());
    }

    Date markAllDate = null;

    markAllDate = userSession.getMarkAllTime();
    if (markAllDate == null) {
        //First date mentioned in Java API
        GregorianCalendar gc = new GregorianCalendar(1970, 0, 1);
        markAllDate = gc.getTime();
    }
    /*Date lastVisitDate = userSession.getLastVisit();
            
    Date compareDate;
    if (markAllDate == null)
    {
      System.out.println("LastVisit setting to false,markDate is null ");
      compareDate = lastVisitDate;
    }
    else
    {
      if (lastVisitDate.getTime() > markAllDate.getTime())
      {
    System.out.println("LastVisit setting to false ");
    compareDate = lastVisitDate;
      }
      else
      {
    System.out.println("markAll setting to false ");   
    compareDate = markAllDate;
      }
    }*/
    TopicMarkTimeDAO tmark = DataAccessDriver.getInstance().newTopicMarkTimeDAO();

    for (Iterator iter = topics.iterator(); iter.hasNext();) {
        boolean read = false;
        Topic t = (Topic) iter.next();

        Date markTime = null;
        Date compareDate = null;

        //markTime = tmark.selectMarkTime(t.getId(), SessionFacade.getUserSession().getUserId());

        for (Iterator mIter = topicMarkTimes.iterator(); mIter.hasNext();) {
            TopicMarkTimeObj tmObj = (TopicMarkTimeObj) mIter.next();
            if (tmObj.getTopicId() == t.getId()) {
                markTime = tmObj.getMarkTime();
                break;
            }

        }
        if (markTime == null) {
            GregorianCalendar gc = new GregorianCalendar(1970, 0, 1);
            markTime = gc.getTime();
        }

        if (markAllDate.getTime() > markTime.getTime()) {
            compareDate = markAllDate;
        } else {
            compareDate = markTime;
        }
        System.out.println("For topic id " + t.getId() + " compareDate is " + compareDate.toString());
        //Mallika - changing line below from lastVisit to compareDate.getTime()         
        if (checkUnread && t.getLastPostTimeInMillis().getTime() > compareDate.getTime()) {
            if (topicsTracking.containsKey(new Integer(t.getId()))) {
                read = (t.getLastPostTimeInMillis()
                        .getTime() == ((Long) topicsTracking.get(new Integer(t.getId()))).longValue());
            }
        } else {
            read = true;
        }

        if (t.getTotalReplies() + 1 > postsPerPage) {
            t.setPaginate(true);
            t.setTotalPages(new Double(Math.floor(t.getTotalReplies() / postsPerPage)));
        } else {
            t.setPaginate(false);
            t.setTotalPages(new Double(0));
        }

        // Check if this is a hot topic
        t.setHot(t.getTotalReplies() >= hotBegin);

        t.setRead(read);
        newTopics.add(t);
    }

    return newTopics;
}

From source file:org.alfresco.mobile.android.application.fragments.search.AdvancedSearchFragment.java

private static void addParameter(StringBuilder builder, String key, GregorianCalendar calendar) {
    if (calendar == null) {
        return;/*from w w w . ja v a2  s . c om*/
    }
    if (builder.length() != 0) {
        builder.append(", ");
    }
    builder.append(key);
    builder.append(":");
    builder.append(new SimpleDateFormat("yyyy-MM-dd").format(calendar.getTime()));
}

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
 * //  ww w .  j av a 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();
}