List of usage examples for java.util GregorianCalendar getTime
public final Date getTime()
Date
object representing this Calendar
's time value (millisecond offset from the Epoch"). From source file:com.sammyun.util.DateUtil.java
/** * ??// w w w.j av a2 s .c om * * @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 o m*/ * * @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:com.sammyun.util.DateUtil.java
/** * ?datas,datas?0??datasdatas0??datas//from w w w . j a v a 2s . c o m * * @param ? * @return */ public static Date getDate(int datas) { GregorianCalendar calendar = new GregorianCalendar(); calendar.add(GregorianCalendar.DATE, datas); String begin = new java.sql.Date(calendar.getTime().getTime()).toString(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Date beginDate = null; try { beginDate = sdf.parse(begin); } catch (ParseException e) { e.printStackTrace(); } return beginDate; }
From source file:org.jkcsoft.web.struts.http.controllers.HttpHelper.java
public static Timestamp getParameterValueAsDate(HttpServletRequest request, String base, boolean parseDay) { int yr = HttpHelper.getParameterValueAsInt(request, base + "Yr", 0); if (yr > 0) { int mth = HttpHelper.getParameterValueAsInt(request, base + "Mth", 0); int day = 0; if (parseDay) { day = HttpHelper.getParameterValueAsInt(request, base + "Day", 0); }/*from w w w . j a va 2 s. c o m*/ GregorianCalendar cal = new GregorianCalendar(yr, mth - 1, day);// mth 0 based return new Timestamp(cal.getTime().getTime()); } return null; }
From source file:org.jkcsoft.web.struts.http.controllers.HttpHelper.java
/** * @param request// www.j av a 2 s.c om * @param base */ public static Timestamp getParameterValueAsTimestamp(HttpServletRequest request, String base) { int yr = HttpHelper.getParameterValueAsInt(request, base + "Yr", 0); if (yr > 0) { int mth = HttpHelper.getParameterValueAsInt(request, base + "Mth", 0); int day = HttpHelper.getParameterValueAsInt(request, base + "Day", 0); int hr = HttpHelper.getParameterValueAsInt(request, base + "Hr", 0); int min = HttpHelper.getParameterValueAsInt(request, base + "Min", 0); GregorianCalendar cal = new GregorianCalendar(yr, mth - 1, day, hr, min);// mth 0 based return new Timestamp(cal.getTime().getTime()); } return null; }
From source file:org.apache.hadoop.fs.azure.AzureBlobStorageTestAccount.java
private static String generateSAS(CloudBlobContainer container, boolean readonly) throws Exception { // Create a container if it does not exist. container.createIfNotExists();//from w w w .j a va 2 s . co m // Create a new shared access policy. SharedAccessBlobPolicy sasPolicy = new SharedAccessBlobPolicy(); // Create a UTC Gregorian calendar value. GregorianCalendar calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC")); // Specify the current time as the start time for the shared access // signature. // calendar.setTime(new Date()); sasPolicy.setSharedAccessStartTime(calendar.getTime()); // Use the start time delta one hour as the end time for the shared // access signature. calendar.add(Calendar.HOUR, 10); sasPolicy.setSharedAccessExpiryTime(calendar.getTime()); if (readonly) { // Set READ permissions sasPolicy .setPermissions(EnumSet.of(SharedAccessBlobPermissions.READ, SharedAccessBlobPermissions.LIST)); } else { // Set READ and WRITE permissions. // sasPolicy.setPermissions(EnumSet.of(SharedAccessBlobPermissions.READ, SharedAccessBlobPermissions.WRITE, SharedAccessBlobPermissions.LIST)); } // Create the container permissions. BlobContainerPermissions containerPermissions = new BlobContainerPermissions(); // Turn public access to the container off. containerPermissions.setPublicAccess(BlobContainerPublicAccessType.OFF); container.uploadPermissions(containerPermissions); // Create a shared access signature for the container. String sas = container.generateSharedAccessSignature(sasPolicy, null); // HACK: when the just generated SAS is used straight away, we get an // authorization error intermittently. Sleeping for 1.5 seconds fixes that // on my box. Thread.sleep(1500); // Return to caller with the shared access signature. return sas; }
From source file:org.gcaldaemon.core.GCalUtilities.java
private static final DateTime toOneDayEventDateTime(Date date) throws Exception { // Convert one day event's date to UTC date String text = date.toString(); GregorianCalendar calendar = new GregorianCalendar(UTC); calendar.set(GregorianCalendar.YEAR, Integer.parseInt(text.substring(0, 4))); calendar.set(GregorianCalendar.MONTH, Integer.parseInt(text.substring(4, 6)) - 1); calendar.set(GregorianCalendar.DAY_OF_MONTH, Integer.parseInt(text.substring(6))); calendar.set(GregorianCalendar.HOUR_OF_DAY, 0); calendar.set(GregorianCalendar.MINUTE, 0); calendar.set(GregorianCalendar.SECOND, 0); calendar.set(GregorianCalendar.MILLISECOND, 0); DateTime dateTime = new DateTime(calendar.getTime(), UTC); return dateTime; }
From source file:org.mifos.calendar.CalendarUtils.java
/** * for monthly on date return the next date falling on the same day. If date has passed, pass in the date of next * month, adjust to day number if day number exceed total number of days in month */// w w w . java 2 s. c om public static DateTime getFirstDateForMonthOnDate(final DateTime startDate, final int dayOfMonth) { final GregorianCalendar gc = new GregorianCalendar(); gc.setTime(startDate.toDate()); int dt = gc.get(GregorianCalendar.DATE); // if date passed in, is after the date on which schedule has to // lie, move to next month if (dt > dayOfMonth) { gc.add(GregorianCalendar.MONTH, 1); } // set the date on which schedule has to lie int M1 = gc.get(GregorianCalendar.MONTH); gc.set(GregorianCalendar.DATE, dayOfMonth); int M2 = gc.get(GregorianCalendar.MONTH); int daynum = dayOfMonth; while (M1 != M2) { gc.set(GregorianCalendar.MONTH, gc.get(GregorianCalendar.MONTH) - 1); gc.set(GregorianCalendar.DATE, daynum - 1); M2 = gc.get(GregorianCalendar.MONTH); daynum--; } return new DateTime(gc.getTime()); }
From source file:org.etudes.jforum.view.forum.common.TopicsCommon.java
/** * Prepare the topics for listing./*from w w w.j a v a 2s. c om*/ * This method does some preparation for a set ot <code>net.jforum.entities.Topic</code> * instances for the current user, like verification if the user already * read the topic, if pagination is a need and so on. * * @param topics The topics to process * @return The post-processed topics. */ public static List prepareTopics(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; 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; } }*/ boolean facilatator = JForumUserUtil.isJForumFacilitator(UserDirectoryService.getCurrentUser().getId()) || SecurityService.isSuperUser(); int prevTopicForumId = -1; Date currentTime = new Date(System.currentTimeMillis()); for (Iterator iter = topics.iterator(); iter.hasNext();) { boolean read = false; boolean markedNotRead = false; Topic t = (Topic) iter.next(); if (!facilatator) { // ignore topics with invalid dates if ((t.getStartDate() != null) && (t.getEndDate() != null)) { if (t.getStartDate().after(t.getEndDate())) { iter.remove(); continue; } } if ((t.getStartDate() != null) && (t.getAllowUntilDate() != null)) { if (t.getStartDate().after(t.getAllowUntilDate())) { iter.remove(); continue; } } if ((t.getEndDate() != null) && (t.getAllowUntilDate() != null)) { if (t.getEndDate().after(t.getAllowUntilDate())) { iter.remove(); continue; } } // check for coursemap access JForumService jforumService = (JForumService) ComponentManager .get("org.etudes.api.app.jforum.JForumService"); if ((t.isGradeTopic() || t.isExportTopic()) && jforumService != null) { Boolean checkAccess = jforumService.checkItemAccess( ToolManager.getCurrentPlacement().getContext(), ConfigKeys.CM_ID_TOPIC + "-" + String.valueOf(t.getId()), userSession.getSakaiUserId()); if (!checkAccess) { t.setBlocked(true); t.setBlockedByTitle( jforumService.getItemAccessMessage(ToolManager.getCurrentPlacement().getContext(), ConfigKeys.CM_ID_TOPIC + "-" + String.valueOf(t.getId()), userSession.getSakaiUserId())); t.setBlockedByDetails( jforumService.getItemAccessDetails(ToolManager.getCurrentPlacement().getContext(), ConfigKeys.CM_ID_TOPIC + "-" + String.valueOf(t.getId()), userSession.getSakaiUserId())); } } if (t.getStartDate() != null) { // consider topics special access List<SpecialAccess> topicsSpecialAccessList = DataAccessDriver.getInstance() .newSpecialAccessDAO().selectByTopic(t.getForumId(), t.getId()); Date curDate = new Date(System.currentTimeMillis()); boolean specialAccessUser = false; boolean specialAccessUserAccess = false; t.setSpecialAccessList(topicsSpecialAccessList); if (topicsSpecialAccessList.size() > 0) { for (SpecialAccess sa : topicsSpecialAccessList) { if (sa.getUserIds().contains(userSession.getUserId())) { specialAccessUser = true; if (!sa.isOverrideStartDate()) { sa.setStartDate(t.getStartDate()); } if (!sa.isOverrideEndDate()) { sa.setEndDate(t.getEndDate()); } /*if (!sa.isOverrideLockEndDate()) { sa.setLockOnEndDate(t.isLockTopic()); }*/ if (!sa.isOverrideAllowUntilDate()) { sa.setAllowUntilDate(t.getAllowUntilDate()); } if (sa.getStartDate() == null || curDate.after(sa.getStartDate())) { specialAccessUserAccess = true; } break; } } } if (specialAccessUser) { if (!specialAccessUserAccess) { iter.remove(); continue; } } else { if (t.getStartDate().after(currentTime)) { iter.remove(); continue; } } } else if ((t.getStartDate() == null) && (t.getEndDate() != null || t.getAllowUntilDate() != null)) { // consider topics special access List<SpecialAccess> topicsSpecialAccessList = DataAccessDriver.getInstance() .newSpecialAccessDAO().selectByTopic(t.getForumId(), t.getId()); Date curDate = new Date(System.currentTimeMillis()); boolean specialAccessUser = false; boolean specialAccessUserAccess = false; t.setSpecialAccessList(topicsSpecialAccessList); if (topicsSpecialAccessList.size() > 0) { for (SpecialAccess sa : topicsSpecialAccessList) { if (sa.getUserIds().contains(userSession.getUserId())) { specialAccessUser = true; if (!sa.isOverrideStartDate()) { sa.setStartDate(t.getStartDate()); } if (!sa.isOverrideEndDate()) { sa.setEndDate(t.getEndDate()); } /*if (!sa.isOverrideLockEndDate()) { sa.setLockOnEndDate(t.isLockTopic()); }*/ if (!sa.isOverrideAllowUntilDate()) { sa.setAllowUntilDate(t.getAllowUntilDate()); } if (sa.getStartDate() == null || curDate.after(sa.getStartDate())) { specialAccessUserAccess = true; } break; } } } if (specialAccessUser) { if (!specialAccessUserAccess) { iter.remove(); continue; } } else { // continue; } } } Date markTime = null; Date compareDate = null; if (prevTopicForumId != t.getForumId()) { topicMarkTimes = null; topicMarkTimes = DataAccessDriver.getInstance().newTopicMarkTimeDAO() .selectTopicMarkTimes(t.getForumId(), userSession.getUserId()); } //Check if topicId is in mark read list for (Iterator mIter = topicMarkTimes.iterator(); mIter.hasNext();) { TopicMarkTimeObj tmObj = (TopicMarkTimeObj) mIter.next(); if (tmObj.getTopicId() == t.getId()) { markTime = tmObj.getMarkTime(); if (!tmObj.isRead()) { markedNotRead = true; } 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()); } if (markedNotRead) { read = false; } } else { if (markedNotRead) { read = false; } 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); prevTopicForumId = t.getForumId(); newTopics.add(t); } return newTopics; }
From source file:com.fatminds.vaadin.cmis.property.CalendarPropertyConverter.java
@Override public Date format(GregorianCalendar value) { if (value == null) { return null; }/*from w w w . j a va 2 s . com*/ return value.getTime(); }