List of usage examples for java.util Calendar getTimeInMillis
public long getTimeInMillis()
From source file:bookUtilities.AddBookServlet.java
private JSONObject addBook(String title, String cover, String author, String genre, String description, String language, String publisher, String fileURL) { JSONObject messageToReturn = new JSONObject(); try {/*from w ww .j a v a 2s . com*/ Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); Connection con = DriverManager.getConnection("jdbc:sqlserver://localhost;user=sa;password=nopw"); Statement st = con.createStatement(); Calendar someDate = Calendar.getInstance(); someDate.setTime(new Date()); Timestamp stamp = new Timestamp(someDate.getTimeInMillis()); String query = "DECLARE @newId UNIQUEIDENTIFIER; " + "SET @newid = NEWID(); " + "INSERT INTO [HardCover].[dbo].[Book] " + "VALUES (@newid, '" + title + "', '" + cover + "', '" + stamp + "', 5, 0, '" + language + "', '" + description + "', '" + publisher + "', 1); "; String[] authors = author.split(", "); String[] genres = genre.split(", "); String[] files = fileURL.split(", "); for (String s : authors) { query += "INSERT INTO [HardCover].[dbo].[Author] (AuthorName, BookId)" + "VALUES('" + s + "', @newid); "; } for (String s : genres) { query += "INSERT INTO [HardCover].[dbo].[Genre] (Genre, BookId)" + "VALUES('" + s + "', @newid); "; } for (String s : files) { query += "INSERT INTO [HardCover].[dbo].[BookFileType] (FileType, DownloadLink, BookId)" + "VALUES('pdf', '" + s + "', @newid); "; } st.executeUpdate(query); messageToReturn.put("message", "success"); } catch (Exception e) { System.out.println(e.getMessage()); } return messageToReturn; }
From source file:net.duckling.ddl.service.resource.impl.PageLockProvider.java
public synchronized long getLeftTimeOfPageLock(int tid, int rid) { PageLock lock = getPageLock(tid, rid); Date timeOut = DateUtils.addMinutes(lock.getLastAccess(), this.timeOutInterval); Calendar calendardate1 = Calendar.getInstance(); calendardate1.setTime(new Date()); Calendar calendardate2 = Calendar.getInstance(); calendardate2.setTime(timeOut);/*from w w w. j av a 2 s .c o m*/ return (calendardate2.getTimeInMillis() - calendardate1.getTimeInMillis()) / 1000; }
From source file:de.fhg.fokus.odp.categoriesgrid.CategoriesGrid.java
/** * Search.// www .j ava 2s. c om * * @param response * the response * @param request * the request */ @ActionMapping(params = "action=categorySearch") public void search(ActionResponse response, ActionRequest request) { String categoryName = request.getParameter("categoryName"); Query query = new Query(); Calendar cal = Calendar.getInstance(); query.getCategories().add(categoryName + ":#:" + cal.getTimeInMillis()); response.setEvent(new QName("http://fokus.fraunhofer.de/odplatform", "querydatasets"), query); ThemeDisplay td = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); String location = td.getPortalURL(); Layout layout = td.getLayout(); try { if (layout.isPublicLayout()) { location += td.getPathFriendlyURLPublic(); } location += layout.hasScopeGroup() ? layout.getScopeGroup().getFriendlyURL() : layout.getGroup().getFriendlyURL(); location += "/suchen"; response.sendRedirect(location); } catch (PortalException e) { LOG.error(e.getMessage()); } catch (SystemException e) { LOG.error(e.getMessage()); } catch (IOException e) { LOG.error(e.getMessage()); } }
From source file:nl.surfnet.coin.teams.service.impl.TeamInviteServiceHibernateImplTest.java
@Test public void testFindAllInvitationById() throws Exception { Invitation invitation = new Invitation(email, team.getId()); Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DAY_OF_WEEK, -20); invitation.setTimestamp(calendar.getTimeInMillis()); String hash = invitation.getInvitationHash(); assertNull(teamInviteService.findInvitationByInviteId(hash)); teamInviteService.saveOrUpdate(invitation); }
From source file:nl.surfnet.coin.teams.service.impl.TeamInviteServiceHibernateImplTest.java
@Test public void testCleanupExpiredInvitations() throws Exception { Invitation oldInvitation = new Invitation(email, team.getId()); Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.MONTH, -2); oldInvitation.setTimestamp(calendar.getTimeInMillis()); Invitation newInvitation = new Invitation("coincalendar@yahoo.com", team.getId()); assertEquals(0, teamInviteService.findAll().size()); teamInviteService.saveOrUpdate(oldInvitation); teamInviteService.saveOrUpdate(newInvitation); assertEquals(2, teamInviteService.findAll().size()); teamInviteService.cleanupExpiredInvitations(); assertEquals(1, teamInviteService.findAll().size()); }
From source file:net.sf.dynamicreports.test.jasper.chart.TimeSeriesChartTest.java
@Override protected JRDataSource createDataSource() { DRDataSource dataSource = new DRDataSource("field1", "field2", "field3"); Calendar c = Calendar.getInstance(); c.setTime(new Date()); for (int i = 0; i < 4; i++) { dataSource.add(c.getTime(), new Timestamp(c.getTimeInMillis()), i + 1); dataSource.add(c.getTime(), new Timestamp(c.getTimeInMillis()), i + 1); c.add(Calendar.DAY_OF_MONTH, 1); }//w ww. j a v a 2 s. c o m return dataSource; }
From source file:org.opencastproject.remotetest.server.FailingPreProcessingWorkflowTest.java
/** * Adds a new recording event to the scheduling service and returns the event id. * // w w w .j av a 2s .c o m * @param start * start date * @param end * end date * @return the event identifier */ private String scheduleEvent(Date start, Date end) throws Exception { HttpPut request = new HttpPut(BASE_URL + "/scheduler"); // Create the request body Calendar c = Calendar.getInstance(); c.roll(Calendar.MINUTE, 1); long startTime = c.getTimeInMillis(); c.roll(Calendar.MINUTE, 1); long endTime = c.getTimeInMillis(); String eventXml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><event>" + "<contributor>demo contributor</contributor><creator>demo creator</creator>" + "<startDate>{start}</startDate><endDate>{stop}</endDate><device>{device}</device>" + "<language>en</language><license>creative commons</license><resources>vga, audio</resources>" + "<title>demo title</title><additionalMetadata><metadata id=\"0\"><key>location</key>" + "<value>demo location</value></metadata><metadata id=\"0\"><key>org.opencastproject.workflow.definition</key>" + "<value>" + WORKFLOW_DEFINITION_ID + "</value></metadata></additionalMetadata></event>"; eventXml = eventXml.replace("{device}", CAPTURE_AGENT_ID).replace("{start}", Long.toString(startTime)) .replace("{stop}", Long.toString(endTime)); // Prepare the request List<NameValuePair> formParams = new ArrayList<NameValuePair>(); formParams.add(new BasicNameValuePair("event", eventXml)); request.setEntity(new UrlEncodedFormEntity(formParams, "UTF-8")); // Submit and check the response HttpResponse response = client.execute(request); assertEquals(HttpStatus.SC_CREATED, response.getStatusLine().getStatusCode()); String responseBody = StringUtils.trimToNull(EntityUtils.toString(response.getEntity())); assertNotNull(responseBody); String eventId = StringUtils.trimToNull( (String) Utils.xpath(responseBody, "/*[local-name() = 'event']/@id", XPathConstants.STRING)); assertNotNull("No event id found", eventId); return eventId; }
From source file:org.teiid.resource.adapter.google.dataprotocol.GoogleDataProtocolAPI.java
static Object convertValue(Calendar cal, Object object, SpreadsheetColumnType type) { switch (type) { case DATE://w ww. java 2 s . c o m case DATETIME: if (object instanceof String) { String stringVal = (String) object; if (stringVal.startsWith("Date(") && stringVal.endsWith(")")) { //$NON-NLS-1$ //$NON-NLS-2$ String[] parts = stringVal.substring(5, stringVal.length() - 1).split(","); //$NON-NLS-1$ if (cal == null) { cal = Calendar.getInstance(); } cal.clear(); if (type == SpreadsheetColumnType.DATETIME) { cal.set(Integer.valueOf(parts[0]), Integer.valueOf(parts[1]), Integer.valueOf(parts[2]), Integer.valueOf(parts[3]), Integer.valueOf(parts[4]), Integer.valueOf(parts[5])); object = new Timestamp(cal.getTimeInMillis()); } else { cal.set(Integer.valueOf(parts[0]), Integer.valueOf(parts[1]), Integer.valueOf(parts[2])); object = new Date(cal.getTimeInMillis()); } } } break; case TIMEOFDAY: if (object instanceof List<?>) { List<Double> doubleVals = (List<Double>) object; if (cal == null) { cal = Calendar.getInstance(); } cal.clear(); cal.set(Calendar.YEAR, 1970); cal.set(Calendar.MONTH, Calendar.JANUARY); cal.set(Calendar.DAY_OF_MONTH, 1); cal.set(Calendar.MILLISECOND, 0); cal.set(Calendar.HOUR, doubleVals.get(0).intValue()); cal.set(Calendar.MINUTE, doubleVals.get(1).intValue()); cal.set(Calendar.SECOND, doubleVals.get(2).intValue()); //TODO: it's not proper to convey the millis on a time value cal.set(Calendar.MILLISECOND, doubleVals.get(3).intValue()); object = new Time(cal.getTimeInMillis()); } break; } return object; }
From source file:nl.surfnet.coin.teams.service.impl.TeamInviteServiceHibernateImplTest.java
@Test public void testDonotFindExpiredInvitationByInviteId() throws Exception { Invitation invitation = new Invitation(email, team.getId()); Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DAY_OF_WEEK, -16); invitation.setTimestamp(calendar.getTimeInMillis()); String hash = invitation.getInvitationHash(); assertEquals(0, teamInviteService.findAll().size()); assertNull("Nothing saved yet", teamInviteService.findInvitationByInviteId(hash)); teamInviteService.saveOrUpdate(invitation); assertEquals(1, teamInviteService.findAll().size()); assertNull("Don't find expired", teamInviteService.findInvitationByInviteId(hash)); }
From source file:gxu.software_engineering.shen10.market.service.UserServiceTest.java
@Test public void testSync() { Calendar c = Calendar.getInstance(); c.set(2013, Calendar.JUNE, 20); List<User> users = userService.sync(c.getTimeInMillis(), 40); System.err.println(users.size()); assertThat(users.size() > 4, is(true)); }