List of usage examples for java.util Calendar toString
@Override
public String toString()
From source file:Main.java
public static void main(String[] args) { Calendar cal = Calendar.getInstance(); System.out.println("Calendar:" + cal.toString()); Date d = cal.getTime();//w ww.ja va2 s . c o m SimpleDateFormat sdf = new SimpleDateFormat("DD/MM/yyyy HH:mm:ss"); System.out.println(sdf.format(d)); SimpleDateFormat sdfNew = new SimpleDateFormat("HH:mm:ss"); System.out.println(sdfNew.format(d)); }
From source file:J2METimeServer.java
public static void main(String[] args) { try {//w w w . j a v a 2 s. co m Calendar cal = Calendar.getInstance(); DatagramConnection receiver = (DatagramConnection) Connector.open("datagram://"); byte[] buffer = new byte[256]; Datagram dgram = receiver.newDatagram(buffer, buffer.length); for (;;) { dgram.setLength(buffer.length); receiver.receive(dgram); cal.setTime(new Date()); String time = cal.toString(); byte[] dataBytes = time.getBytes(); System.arraycopy(dataBytes, 0, buffer, 0, dataBytes.length); dgram.setLength(dataBytes.length); receiver.send(dgram); } } catch (IOException ex) { System.out.println("IOException: " + ex); } }
From source file:Main.java
public static int[] getSchoolCalDate(int year, int month, int day, int week, int dayOfWeek) { Calendar cal = Calendar.getInstance(); cal.set(year, month - 1, day);//from w ww .jav a 2s . co m Log.d(TAG, "Date: " + cal.toString()); Log.d(TAG, "year: " + year); Log.d(TAG, "month: " + month); Log.d(TAG, "day: " + day); cal.add(Calendar.DATE, -offset(cal.get(Calendar.DAY_OF_WEEK))); int count = (week - 1) * 7 + dayOfWeek - 1; Log.d(TAG, "count: " + count); cal.add(Calendar.DATE, count); int result[] = { cal.get(Calendar.YEAR), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.DAY_OF_MONTH) }; return result; }
From source file:Main.java
private static String findNext(Calendar cal, String[] arr) { for (String s : arr) { if (isBefore(cal, s)) { return s; }//from ww w . j a v a 2 s .c o m } Log.i("utils.java findNext", "no next bus found for date:" + cal.toString()); return null; }
From source file:org.apache.usergrid.apm.service.NetworkTestData.java
public static void populateSQSWithTestData(int numMin, Calendar startTime, int numDevices, App app) { log.info("Populating SQS with Test Data. Start Time : " + startTime.toString() + " Duration : " + numMin + "mins. AppId: " + app.getFullAppName()); MetricsInjestionServiceSQSImpl sqsImpl = (MetricsInjestionServiceSQSImpl) ServiceFactory .getMetricsInjestionServiceInstance(); for (int j = 0; j < numMin; j++) { startTime.add(Calendar.MINUTE, 1); for (int l = 0; l < numDevices; l++) {//put 10 random beans startTime.set(Calendar.SECOND, generator.nextInt(60)); Calendar endTime = Calendar.getInstance(); endTime.setTime(startTime.getTime()); endTime.add(Calendar.SECOND, generator.nextInt(60)); Date start = startTime.getTime(); Date end = endTime.getTime(); ClientMetricsEnvelope envelope = generateWebServiceMetricsBeanMessageEnvelope( app.getInstaOpsApplicationId(), start, end); sqsImpl.sendData(app.getFullAppName(), envelope); }/*from www . j a v a2 s.c om*/ } }
From source file:Main.java
public static Calendar getCalendarForTime(int repeatMode, int dayOfWeek, int hour, int minute, int second) { Calendar calendarNow = Calendar.getInstance(); Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.HOUR_OF_DAY, hour); calendar.set(Calendar.MINUTE, minute); calendar.set(Calendar.SECOND, second); calendar.set(Calendar.MILLISECOND, 0); if (repeatMode == 2) { int dayOfWeekAndroid = 0; // 7 stands for sunday for interface, but for android, sunday stands for 1. dayOfWeekAndroid = dayOfWeek % 7 + 1; calendar.set(Calendar.DAY_OF_WEEK, dayOfWeekAndroid); }//from w w w . j a v a 2s . c o m // make sure the desire alarm time is in future. int tryCount = 0; int tryCountMax = 62; while (calendar.getTimeInMillis() < calendarNow.getTimeInMillis() && tryCount < tryCountMax) { if (repeatMode == 1) { calendar.add(Calendar.DAY_OF_YEAR, 1); } else if (repeatMode == 2) { calendar.add(Calendar.DAY_OF_YEAR, 7); } tryCount++; } Log.v("cpeng", "getCalendearForTime target info: " + calendar.toString()); return calendar; }
From source file:org.sipfoundry.sipxconfig.vm.VoicemailTest.java
public void testGetDate() throws ParseException { DateFormat formatter = new SimpleDateFormat(MessageDescriptor.TIMESTAMP_FORMAT); Date date = formatter.parse("Tue, 9-Jan-2007 02:33:00 PM EST"); Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("EST"), Locale.ENGLISH); cal.setTime(date);//from ww w . ja va 2 s .c o m cal.toString(); assertEquals(14, cal.get(Calendar.HOUR_OF_DAY)); }
From source file:org.nuxeo.cm.service.synchronization.MailboxSyncTestListener.java
public void handleEvent(Event event) throws ClientException { String eventName = event.getName(); String failMessage = "Error handling event " + eventName + ": "; String mbTitle = (String) event.getContext() .getProperty(MailboxSynchronizationConstants.EVENT_CONTEXT_MAILBOX_TITLE); assertFalse(failMessage + "Empty mailbox title", StringUtils.isEmpty(mbTitle)); Calendar synchronizerDate = (Calendar) event.getContext() .getProperty(MailboxSynchronizationConstants.EVENT_CONTEXT_SYNCHRONIZED_DATE); assertFalse(failMessage + "Empty synchronizer date for mailbox with title " + mbTitle, synchronizerDate == null || StringUtils.isEmpty(synchronizerDate.toString())); String synchronizerId = (String) event.getContext() .getProperty(MailboxSynchronizationConstants.EVENT_CONTEXT_SYNCHRONIZER_ID); assertFalse(failMessage + "Empty synchronizer id for mailbox with title " + mbTitle, StringUtils.isEmpty(synchronizerId)); DocumentModel mbDoc = ((DocumentEventContext) event.getContext()).getSourceDocument(); assertNotNull(failMessage + "Null document for mailbox with title " + mbTitle, mbDoc); String mbPath = mbDoc.getPathAsString(); assertFalse(failMessage + "Empty path for mailbox document with title " + mbTitle, StringUtils.isEmpty(mbPath)); if ("userDirectory".equals( event.getContext().getProperty(MailboxSynchronizationConstants.EVENT_CONTEXT_DIRECTORY_NAME))) { if (MailboxSynchronizationConstants.EventNames.onMailboxCreated.equals(eventName)) { mbCreatedForUser.add(mbPath); } else if (MailboxSynchronizationConstants.EventNames.onMailboxDeleted.equals(eventName)) { mbDeletedForUser.add(mbPath); } else if (MailboxSynchronizationConstants.EventNames.onMailboxUpdated.equals(eventName)) { mbUpdatedForUser.add(mbPath); }//w w w .ja v a 2 s. com } else if ("groupDirectory".equals( event.getContext().getProperty(MailboxSynchronizationConstants.EVENT_CONTEXT_DIRECTORY_NAME))) { if (MailboxSynchronizationConstants.EventNames.onMailboxCreated.equals(eventName)) { mbCreatedForGroup.add(mbPath); } else if (MailboxSynchronizationConstants.EventNames.onMailboxDeleted.equals(eventName)) { mbDeletedForGroup.add(mbPath); } else if (MailboxSynchronizationConstants.EventNames.onMailboxUpdated.equals(eventName)) { mbUpdatedForGroup.add(mbPath); } } }
From source file:com.swdouglass.joid.Association.java
public boolean hasExpired() { Calendar now = Calendar.getInstance(); Calendar expired = Calendar.getInstance(); expired.setTime(issuedDate);// w ww . java 2 s . com expired.add(Calendar.SECOND, lifetime.intValue()); if (log.isDebugEnabled()) { log.debug("now: " + now.toString()); log.debug("issuedDate: " + issuedDate.toString()); log.debug("expired: " + expired.toString()); log.debug("now.after(expired): " + now.after(expired)); } return now.after(expired); }
From source file:com.marklogic.client.functionaltest.TestJacksonDateTimeFormat.java
public void validateSpecialArtifactDateTime(SpecialArtifactDateTime artifact, String artifactName, long longId, Calendar datetime) { System.out.println("Argumnt : " + datetime.toString()); System.out.println("Jackson POJO : " + artifact.getExpiryDate().toString()); assertNotNull("Artifact object should never be Null", artifact); assertNotNull("Id should never be Null", artifact.id); assertEquals("Id of the object is ", longId, artifact.getId()); assertEquals("Name of the object is ", artifactName, artifact.getName()); assertEquals("Inventory of the object is ", 1000, artifact.getInventory()); assertEquals("Company name of the object is ", artifactName, artifact.getManufacturer().getName()); assertEquals("Web site of the object is ", "http://www.acme.com", artifact.getManufacturer().getWebsite()); //Validate the calendar object's field, instead of object or string comparisions. assertEquals("Expiry date: MONTH ", datetime.get(Calendar.MONTH), artifact.getExpiryDate().get(Calendar.MONTH)); assertEquals("Expiry date: DAY_OF_MONTH ", datetime.get(Calendar.DAY_OF_MONTH), artifact.getExpiryDate().get(Calendar.DAY_OF_MONTH)); assertEquals("Expiry date: YEAR ", datetime.get(Calendar.YEAR), artifact.getExpiryDate().get(Calendar.YEAR)); assertEquals("Expiry date: HOUR ", datetime.get(Calendar.HOUR), artifact.getExpiryDate().get(Calendar.HOUR)); assertEquals("Expiry date: MINUTE ", datetime.get(Calendar.MINUTE), artifact.getExpiryDate().get(Calendar.MINUTE)); assertEquals("Expiry date: SECOND ", datetime.get(Calendar.SECOND), artifact.getExpiryDate().get(Calendar.SECOND)); assertEquals(-87.966, artifact.getManufacturer().getLongitude(), 0.00); assertEquals(41.998, artifact.getManufacturer().getLatitude(), 0.00); }