List of usage examples for java.util GregorianCalendar setTimeInMillis
public void setTimeInMillis(long millis)
From source file:GetLeadChanges.java
public static void main(String[] args) { System.out.println("Executing Get Lead Changes"); try {//from w w w. ja va 2 s . com URL marketoSoapEndPoint = new URL("CHANGE ME" + "?WSDL"); String marketoUserId = "CHANGE ME"; String marketoSecretKey = "CHANGE ME"; QName serviceName = new QName("http://www.marketo.com/mktows/", "MktMktowsApiService"); MktMktowsApiService service = new MktMktowsApiService(marketoSoapEndPoint, serviceName); MktowsPort port = service.getMktowsApiSoapPort(); // Create Signature DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); String text = df.format(new Date()); String requestTimestamp = text.substring(0, 22) + ":" + text.substring(22); String encryptString = requestTimestamp + marketoUserId; SecretKeySpec secretKey = new SecretKeySpec(marketoSecretKey.getBytes(), "HmacSHA1"); Mac mac = Mac.getInstance("HmacSHA1"); mac.init(secretKey); byte[] rawHmac = mac.doFinal(encryptString.getBytes()); char[] hexChars = Hex.encodeHex(rawHmac); String signature = new String(hexChars); // Set Authentication Header AuthenticationHeader header = new AuthenticationHeader(); header.setMktowsUserId(marketoUserId); header.setRequestTimestamp(requestTimestamp); header.setRequestSignature(signature); // Create Request ParamsGetLeadChanges request = new ParamsGetLeadChanges(); ObjectFactory objectFactory = new ObjectFactory(); JAXBElement<Integer> batchSize = objectFactory.createParamsGetLeadActivityBatchSize(10); request.setBatchSize(batchSize); ArrayOfString activities = new ArrayOfString(); activities.getStringItems().add("Visit Webpage"); activities.getStringItems().add("Click Link"); JAXBElement<ArrayOfString> activityFilter = objectFactory .createParamsGetLeadChangesActivityNameFilter(activities); request.setActivityNameFilter(activityFilter); // Create oldestCreateAt timestamp from 5 days ago GregorianCalendar gc = new GregorianCalendar(); gc.setTimeInMillis(new Date().getTime()); gc.add(GregorianCalendar.DAY_OF_YEAR, -5); DatatypeFactory factory = DatatypeFactory.newInstance(); JAXBElement<XMLGregorianCalendar> oldestCreateAtValue = objectFactory .createStreamPositionOldestCreatedAt(factory.newXMLGregorianCalendar(gc)); StreamPosition sp = new StreamPosition(); sp.setOldestCreatedAt(oldestCreateAtValue); request.setStartPosition(sp); SuccessGetLeadChanges result = port.getLeadChanges(request, header); JAXBContext context = JAXBContext.newInstance(SuccessGetLeadChanges.class); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); m.marshal(result, System.out); } catch (Exception e) { e.printStackTrace(); } }
From source file:ScheduleCampaign.java
public static void main(String[] args) { System.out.println("Executing Schedule Campaign"); try {//from ww w . j a v a 2s . c o m URL marketoSoapEndPoint = new URL("CHANGE ME" + "?WSDL"); String marketoUserId = "CHANGE ME"; String marketoSecretKey = "CHANGE ME"; QName serviceName = new QName("http://www.marketo.com/mktows/", "MktMktowsApiService"); MktMktowsApiService service = new MktMktowsApiService(marketoSoapEndPoint, serviceName); MktowsPort port = service.getMktowsApiSoapPort(); // Create Signature DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); String text = df.format(new Date()); String requestTimestamp = text.substring(0, 22) + ":" + text.substring(22); String encryptString = requestTimestamp + marketoUserId; SecretKeySpec secretKey = new SecretKeySpec(marketoSecretKey.getBytes(), "HmacSHA1"); Mac mac = Mac.getInstance("HmacSHA1"); mac.init(secretKey); byte[] rawHmac = mac.doFinal(encryptString.getBytes()); char[] hexChars = Hex.encodeHex(rawHmac); String signature = new String(hexChars); // Set Authentication Header AuthenticationHeader header = new AuthenticationHeader(); header.setMktowsUserId(marketoUserId); header.setRequestTimestamp(requestTimestamp); header.setRequestSignature(signature); // Create Request ParamsScheduleCampaign request = new ParamsScheduleCampaign(); request.setProgramName("Trav-Demo-Program"); request.setCampaignName("Batch Campaign Example"); // Create setCampaignRunAt timestamp GregorianCalendar gc = new GregorianCalendar(); gc.setTimeInMillis(new Date().getTime()); DatatypeFactory factory = DatatypeFactory.newInstance(); ObjectFactory objectFactory = new ObjectFactory(); JAXBElement<XMLGregorianCalendar> setCampaignRunAtValue = objectFactory .createParamsScheduleCampaignCampaignRunAt(factory.newXMLGregorianCalendar(gc)); request.setCampaignRunAt(setCampaignRunAtValue); request.setCloneToProgramName("TestProgramCloneFromSOAP"); ArrayOfAttrib aoa = new ArrayOfAttrib(); Attrib attrib = new Attrib(); attrib.setName("{{my.message}}"); attrib.setValue("Updated message"); aoa.getAttribs().add(attrib); JAXBElement<ArrayOfAttrib> arrayOfAttrib = objectFactory .createParamsScheduleCampaignProgramTokenList(aoa); request.setProgramTokenList(arrayOfAttrib); SuccessScheduleCampaign result = port.scheduleCampaign(request, header); JAXBContext context = JAXBContext.newInstance(SuccessScheduleCampaign.class); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); m.marshal(result, System.out); } catch (Exception e) { e.printStackTrace(); } }
From source file:BasicTimer.java
public static void main(String[] args) throws Exception { int type = TYPE_REMAINING; BasicTimer timer = new BasicTimer(type); timer.setMax(10000);/* w ww. ja v a2s . c o m*/ GregorianCalendar calendar = new GregorianCalendar(); while (true) { Thread.sleep(1000); if (type == TYPE_CLOCK) { calendar.setTimeInMillis(timer.getTime()); System.out.println("Clock: " + calendar); } else if (type == TYPE_ELAPSED) { System.out.println("Elapsed: " + (timer.getTime() / 1000) + " seconds"); } else if (type == TYPE_REMAINING) { System.out.println("Remaining: " + (timer.getTime() / 1000) + " seconds"); } } }
From source file:Main.java
public static XMLGregorianCalendar longToXMLGregorianCalendar(long time) throws DatatypeConfigurationException { if (time <= 0) { return null; }/*from w ww . j a v a2 s .c om*/ GregorianCalendar cal = new GregorianCalendar(); cal.setTimeInMillis(time); XMLGregorianCalendar newXMLGregorianCalendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(cal); return newXMLGregorianCalendar; }
From source file:Main.java
/** * Calculates the difference in days, rounding the operands down to the nearest day. * Ex. Jan 3rd 12:31 pm - Jan 2nd 4:00 pm * = Jan 3rd - Jan 2nd// ww w. j a v a 2 s . c o m * = 1 day * @return The difference in days. */ public static int differenceInDays(GregorianCalendar minuend, GregorianCalendar subtrahend) { GregorianCalendar minuendFloor = new GregorianCalendar(minuend.get(Calendar.YEAR), minuend.get(Calendar.MONTH), minuend.get(Calendar.DAY_OF_MONTH)); GregorianCalendar subtrahendFloor = new GregorianCalendar(subtrahend.get(Calendar.YEAR), subtrahend.get(Calendar.MONTH), subtrahend.get(Calendar.DAY_OF_MONTH)); GregorianCalendar result = new GregorianCalendar(); result.setTimeInMillis(minuendFloor.getTimeInMillis() - subtrahendFloor.getTimeInMillis()); return result.get(Calendar.DAY_OF_YEAR); }
From source file:Main.java
/** * * @param date//from w ww.j a v a 2 s . co m * @return Converts a java.util.Date into an instance of * XMLGregorianCalendar */ public static XMLGregorianCalendar asXMLGregorianCalendar(java.util.Date date) { if (date == null) { return null; } else { GregorianCalendar gc = new GregorianCalendar(); gc.setTimeInMillis(date.getTime()); return df.newXMLGregorianCalendar(gc); } }
From source file:Main.java
/** * Returns the year (index 0), month (index 1) and day (index 2) of the given timestamp. * @param timestamp the timestamp//from w w w .ja v a2s .c o m * @return the year (index 0), month (index 1) and day (index 2) of the given timestamp */ public static int[] getDayMonthYear(long timestamp) { GregorianCalendar gregorianCalendar = new GregorianCalendar(); gregorianCalendar.setTimeInMillis(timestamp); int day = gregorianCalendar.get(Calendar.DAY_OF_MONTH); int month = gregorianCalendar.get(Calendar.MONTH) + 1; int year = gregorianCalendar.get(Calendar.YEAR); return new int[] { year, month, day }; }
From source file:Main.java
public static XMLGregorianCalendar long2XMLGregorian(long dateAsLong) { DatatypeFactory dataTypeFactory; try {/* ww w . j a va 2 s .co m*/ dataTypeFactory = DatatypeFactory.newInstance(); } catch (DatatypeConfigurationException e) { throw new RuntimeException(e); } GregorianCalendar gc = new GregorianCalendar(); gc.setTimeInMillis(dateAsLong); return dataTypeFactory.newXMLGregorianCalendar(gc); }
From source file:Main.java
/** * Convenience method to format a Date as an XML DateTime String. * * @param date/*from ww w . j a v a2 s . co m*/ * the date to format. * @return the XML representation as a string. */ public static String formatDate(final Date date) { GregorianCalendar calendar = new GregorianCalendar(); calendar.setTimeInMillis(date.getTime()); return formatGregorianCalendar(calendar); }
From source file:Main.java
public static XMLGregorianCalendar timestampToXMLGregorianCalendar(Timestamp t) { if (t == null) { return null; }/*from ww w.j a v a2s . c om*/ GregorianCalendar gc = new GregorianCalendar(); gc.setTimeInMillis(t.getTime()); try { return DatatypeFactory.newInstance().newXMLGregorianCalendar(gc); } catch (DatatypeConfigurationException ex) { return null; } }