List of usage examples for java.util Date getTime
public long getTime()
From source file:Main.java
public static void main(String[] args) throws ParseException { SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss"); long second = 1000l; long minute = 60l * second; long hour = 60l * minute; // parsing input Date date1 = dateFormat.parse("02/26/2015 09:00:00"); Date date2 = dateFormat.parse("02/26/2015 19:30:00"); // calculation long diff = date2.getTime() - date1.getTime(); // printing output System.out.print(String.format("%02d", diff / hour)); System.out.print(":"); System.out.print(String.format("%02d", (diff % hour) / minute)); System.out.print(":"); System.out.print(String.format("%02d", (diff % minute) / second)); }
From source file:Main.java
public static void main(String[] argv) throws Exception { Connection dbConnection = null; PreparedStatement preparedStatement = null; Class.forName(DB_DRIVER);/*from w w w. j av a 2 s . c om*/ dbConnection = DriverManager.getConnection(DB_CONNECTION, DB_USER, DB_PASSWORD); String insertTableSQL = "INSERT INTO Person" + "(USER_ID, USERNAME, CREATED_BY, CREATED_DATE) VALUES" + "(?,?,?,?)"; preparedStatement = dbConnection.prepareStatement(insertTableSQL); preparedStatement.setInt(1, 11); preparedStatement.setString(2, "yourName"); preparedStatement.setString(3, "system"); java.util.Date today = new java.util.Date(); preparedStatement.setTimestamp(4, new java.sql.Timestamp(today.getTime())); preparedStatement.executeUpdate(); preparedStatement.close(); dbConnection.close(); }
From source file:Main.java
public static void main(String args[]) { Date date = new Date(); System.out.println("Date is : " + date); System.out.println("Milliseconds since January 1, 1970, 00:00:00 GMT : " + date.getTime()); }
From source file:Touch.java
public static void main(String[] args) { String[] names = new File(".").list(); Date current = new Date(); for (int i = 0; i < names.length; i++) { File f = new File(names[i]); f.setLastModified(current.getTime()); }/* ww w. ja va 2 s . co m*/ }
From source file:MainClass.java
public static void main(String[] args) throws Exception { String keystoreFile = "keyStoreFile.bin"; String caAlias = "caAlias"; String certToSignAlias = "cert"; String newAlias = "newAlias"; char[] password = new char[] { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h' }; char[] caPassword = new char[] { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h' }; char[] certPassword = new char[] { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h' }; FileInputStream input = new FileInputStream(keystoreFile); KeyStore keyStore = KeyStore.getInstance("JKS"); keyStore.load(input, password);/*from w w w .j av a 2s . c o m*/ input.close(); PrivateKey caPrivateKey = (PrivateKey) keyStore.getKey(caAlias, caPassword); java.security.cert.Certificate caCert = keyStore.getCertificate(caAlias); byte[] encoded = caCert.getEncoded(); X509CertImpl caCertImpl = new X509CertImpl(encoded); X509CertInfo caCertInfo = (X509CertInfo) caCertImpl.get(X509CertImpl.NAME + "." + X509CertImpl.INFO); X500Name issuer = (X500Name) caCertInfo.get(X509CertInfo.SUBJECT + "." + CertificateIssuerName.DN_NAME); java.security.cert.Certificate cert = keyStore.getCertificate(certToSignAlias); PrivateKey privateKey = (PrivateKey) keyStore.getKey(certToSignAlias, certPassword); encoded = cert.getEncoded(); X509CertImpl certImpl = new X509CertImpl(encoded); X509CertInfo certInfo = (X509CertInfo) certImpl.get(X509CertImpl.NAME + "." + X509CertImpl.INFO); Date firstDate = new Date(); Date lastDate = new Date(firstDate.getTime() + 365 * 24 * 60 * 60 * 1000L); CertificateValidity interval = new CertificateValidity(firstDate, lastDate); certInfo.set(X509CertInfo.VALIDITY, interval); certInfo.set(X509CertInfo.SERIAL_NUMBER, new CertificateSerialNumber((int) (firstDate.getTime() / 1000))); certInfo.set(X509CertInfo.ISSUER + "." + CertificateSubjectName.DN_NAME, issuer); AlgorithmId algorithm = new AlgorithmId(AlgorithmId.md5WithRSAEncryption_oid); certInfo.set(CertificateAlgorithmId.NAME + "." + CertificateAlgorithmId.ALGORITHM, algorithm); X509CertImpl newCert = new X509CertImpl(certInfo); newCert.sign(caPrivateKey, "MD5WithRSA"); keyStore.setKeyEntry(newAlias, privateKey, certPassword, new java.security.cert.Certificate[] { newCert }); FileOutputStream output = new FileOutputStream(keystoreFile); keyStore.store(output, password); output.close(); }
From source file:it.unibas.spicybenchmark.Main.java
public static void main(String[] args) { try {//from www . j a v a 2 s. c om String propertiesFile = args[0]; StringBuilder executionTimes = new StringBuilder("--- Execution times: ---\n"); Configuration configuration = DAOConfiguration.loadConfigurationFile(propertiesFile); IDataSourceProxy dataSource = new DAOXsd().loadSchema(configuration.getSchemaAbsolutePath()); LoadXMLFile xmlLoader = new LoadXMLFile(); Date beforeLoadingExpected = new Date(); INode expectedInstanceNode = xmlLoader.loadInstance(dataSource, configuration.getExpectedInstanceAbsolutePath()); Date afterLoadingExpected = new Date(); long loadingExpected = afterLoadingExpected.getTime() - beforeLoadingExpected.getTime(); executionTimes.append("Expected Instance loaded: ").append(loadingExpected).append(" ms\n"); INode translatedInstanceNode = xmlLoader.loadInstance(dataSource, configuration.getTranslatedInstanceAbsolutePath()); Date afterLoadingTranslated = new Date(); long loadingTranslated = afterLoadingTranslated.getTime() - afterLoadingExpected.getTime(); executionTimes.append("Translated Instance loaded: ").append(loadingTranslated).append(" ms\n"); List<String> exclusionList = new DAOExclusionList().loadExclusionList(dataSource, configuration.getExclusionsFileAbsolutePath()); Date startSpicyTime = new Date(); FeatureCollectionGenerator featureCollectionGenerator = new FeatureCollectionGenerator(); FeatureCollection featureCollection = featureCollectionGenerator.generate(expectedInstanceNode, translatedInstanceNode, exclusionList, dataSource, configuration); EvaluateSimilarity evaluator = new EvaluateSimilarity(); SimilarityResult similarityResult = evaluator.getSimilarityResult(featureCollection); similarityResult .setNumberOfNodesInExpectedInstance(new CalculateSize().getNumberOfNodes(expectedInstanceNode)); similarityResult.setNumberOfNodesInTranslatedInstance( new CalculateSize().getNumberOfNodes(translatedInstanceNode)); Date endSpicyTime = new Date(); long spicyExecTime = endSpicyTime.getTime() - startSpicyTime.getTime(); executionTimes.append("Spicy execution time: ").append(spicyExecTime).append(" ms\n"); if (configuration.isTreeEditDistanceValiente()) { Date startValiente = new Date(); similarityResult .setTreeEditDistanceValiente(new TreeEditDistanceGeneratorSimPack().compute(configuration)); Date stopValiente = new Date(); long valienteExecTime = stopValiente.getTime() - startValiente.getTime(); executionTimes.append("Valiente execution time: ").append(valienteExecTime).append(" ms\n"); } if (configuration.isTreeEditDistanceShasha()) { Date startShasha = new Date(); similarityResult.setTreeEditDistanceShasha( new TreeEditDistanceGenerator().computeTreeEditDistance(featureCollection)); Date stopShasha = new Date(); long shashaExecTime = stopShasha.getTime() - startShasha.getTime(); executionTimes.append("Shasha execution time: ").append(shashaExecTime).append(" ms\n"); } // similarityResult.setTopDownOrderedMaximumSubtree(new TopDownOrderedMaximumSubtreeGenerator().compute(configuration)); // similarityResult.setBottomUpMaximumSubtree(new BottomUpMaximumSubtreeGenerator().compute(configuration)); // similarityResult.setJaccard(new JaccardGenerator().compute(expectedInstanceNode, translatedInstanceNode)); Utility.printFinalLog(similarityResult, configuration, executionTimes.toString()); } catch (DAOException ex) { logger.error(ex); } }
From source file:MainClass.java
public static void main(String[] args) throws Exception { Date today = new Date(); long millisecondsPerDay = 24 * 60 * 60 * 1000; URL u = new URL("http://www.java2s.com"); URLConnection uc = u.openConnection(); uc.setIfModifiedSince((new Date(today.getTime() - millisecondsPerDay)).getTime()); InputStream in = new BufferedInputStream(uc.getInputStream()); Reader r = new InputStreamReader(in); int c;//from w w w . j a va 2 s. co m while ((c = r.read()) != -1) { System.out.print((char) c); } }
From source file:module.entities.UsernameChecker.CheckOpengovUsernames.java
/** * @param args the command line arguments *///from w w w . j a va2 s.c o m public static void main(String[] args) throws SQLException, IOException { // args = new String[1]; // args[0] = "searchConf.txt"; Date d = new Date(); long milTime = d.getTime(); long execStart = System.nanoTime(); Timestamp startTime = new Timestamp(milTime); long lStartTime; long lEndTime = 0; int status_id = 1; JSONObject obj = new JSONObject(); if (args.length != 1) { System.out.println("None or too many argument parameters where defined! " + "\nPlease provide ONLY the configuration file name as the only argument."); } else { try { configFile = args[0]; initLexicons(); Database.init(); lStartTime = System.currentTimeMillis(); System.out.println("Opengov username identification process started at: " + startTime); usernameCheckerId = Database.LogUsernameChecker(lStartTime); TreeMap<Integer, String> OpenGovUsernames = Database.GetOpenGovUsers(); HashSet<ReportEntry> report_names = new HashSet<>(); if (OpenGovUsernames.size() > 0) { for (int userID : OpenGovUsernames.keySet()) { String DBusername = Normalizer .normalize(OpenGovUsernames.get(userID).toUpperCase(locale), Normalizer.Form.NFD) .replaceAll("\\p{M}", ""); String username = ""; int type; String[] splitUsername = DBusername.split(" "); if (checkNameInLexicons(splitUsername)) { for (String splText : splitUsername) { username += splText + " "; } type = 1; } else if (checkOrgInLexicons(splitUsername)) { for (String splText : splitUsername) { username += splText + " "; } type = 2; } else { username = DBusername; type = -1; } ReportEntry cerEntry = new ReportEntry(userID, username.trim(), type); report_names.add(cerEntry); } status_id = 2; obj.put("message", "Opengov username checker finished with no errors"); obj.put("details", ""); Database.UpdateOpengovUsersReportName(report_names); lEndTime = System.currentTimeMillis(); } else { status_id = 2; obj.put("message", "Opengov username checker finished with no errors"); obj.put("details", "No usernames needed to be checked"); lEndTime = System.currentTimeMillis(); } } catch (Exception ex) { System.err.println(ex.getMessage()); status_id = 3; obj.put("message", "Opengov username checker encountered an error"); obj.put("details", ex.getMessage().toString()); lEndTime = System.currentTimeMillis(); } } long execEnd = System.nanoTime(); long executionTime = (execEnd - execStart); System.out.println("Total process time: " + (((executionTime / 1000000) / 1000) / 60) + " minutes."); Database.UpdateLogUsernameChecker(lEndTime, status_id, usernameCheckerId, obj); Database.closeConnection(); }
From source file:com.roncoo.pay.thirdpartypay.xinzhongli.api.XzlPayAPI.java
public static void main(String[] args) throws Exception { Date date = new Date(); String tradeamt = "10"; String merchantid = "105799954663750238208"; //??/*ww w . jav a2 s.c o m*/ String orderid = "LS" + date.getTime() + (int) (Math.random() * 10000000); String backurl = "www"; String callbackurl = "www"; String pay_type = "123"; String manualsettle = "1"; String orderInfo = "?"; String settlement_type = "130"; String platform_code = "880002"; String key = "f4fcb30e002211584a199ce6ab200afc3c28920dcddeaa59c0558d4439d30b0758661db6247d0ae0d888e9991c4cbd9564473cf787f05f27ecbb7b3f77d9c797+z.1230e5732e6"; PayInfo payInfo = new PayInfo(); // payInfo.setTradeamt(tradeamt); // payInfo.setMerchantid(merchantid); // payInfo.setOrderid(orderid); // payInfo.setBackurl(callbackurl); // payInfo.setCallbackurl(callbackurl); // payInfo.setPay_type(pay_type); // payInfo.setManualsettle(manualsettle); // payInfo.setOrderInfo(orderInfo); // payInfo.setSettlement_type(settlement_type); // payInfo.setPlatform_code(platform_code); payInfo.setKey(key); // pay(payInfo); // testpay(); }
From source file:calendarevent.CalendarEvent.java
/** * @param args the command line arguments *//*from ww w . j a v a 2 s. c o m*/ public static void main(String[] args) { // TODO code application logic here /* This has to be replaced with the json data coming from the getJsonData() method Expecting the Json will be in the format from the above methid. */ String jsonString = "{\n" + " \"kind\": \"calendar#events\",\n" + " \"etag\": \"\\\"2DaeHpkENZGECFHdcr5l8tYxjD4/QElT1PHkP9d3G5VSndpdEMlSzKE\\\"\",\n" + " \"summary\": \"PushEvents\",\n" + " \"description\": \"Hackathon\",\n" + " \"updated\": \"2014-03-29T22:35:18.495Z\",\n" + " \"timeZone\": \"Asia/Calcutta\",\n" + " \"accessRole\": \"reader\",\n" + " \"items\": [\n" + " {\n" + " \"kind\": \"calendar#event\",\n" + " \"etag\": \"\\\"2DaeHpkENZGECFHdcr5l8tYxjD4/MTM5NjEyNTQwNzcxMTAwMA\\\"\",\n" + " \"id\": \"q28lprjb8ad3m17955lf1p9d48\",\n" + " \"status\": \"confirmed\",\n" + " \"htmlLink\": \"https://www.google.com/calendar/event?eid=cTI4bHByamI4YWQzbTE3OTU1bGYxcDlkNDggM3RvcjdvamZxaWhlamNqNjduOWw0dDhnMmNAZw\",\n" + " \"created\": \"2014-03-29T20:36:47.000Z\",\n" + " \"updated\": \"2014-03-29T20:36:47.711Z\",\n" + " \"summary\": \"Test API\",\n" + " \"creator\": {\n" + " \"email\": \"vrohitrao@gmail.com\",\n" + " \"displayName\": \"Rohith Vallu\"\n" + " },\n" + " \"organizer\": {\n" + " \"email\": \"3tor7ojfqihejcj67n9l4t8g2c@group.calendar.google.com\",\n" + " \"displayName\": \"PushEvents\",\n" + " \"self\": true\n" + " },\n" + " \"start\": {\n" + " \"dateTime\": \"2014-03-30T02:30:00+05:30\"\n" + " },\n" + " \"end\": {\n" + " \"dateTime\": \"2014-03-30T03:30:00+05:30\"\n" + " },\n" + " \"iCalUID\": \"q28lprjb8ad3m17955lf1p9d48@google.com\",\n" + " \"sequence\": 0\n" + " },\n" + " {\n" + " \"kind\": \"calendar#event\",\n" + " \"etag\": \"\\\"2DaeHpkENZGECFHdcr5l8tYxjD4/MTM5NjEzMjUzMjQxNzAwMA\\\"\",\n" + " \"id\": \"jgpue3stuo3js5qlsodob84voo\",\n" + " \"status\": \"confirmed\",\n" + " \"htmlLink\": \"https://www.google.com/calendar/event?eid=amdwdWUzc3R1bzNqczVxbHNvZG9iODR2b28gM3RvcjdvamZxaWhlamNqNjduOWw0dDhnMmNAZw\",\n" + " \"created\": \"2014-03-29T22:35:32.000Z\",\n" + " \"updated\": \"2014-03-29T22:35:32.417Z\",\n" + " \"summary\": \"Test Events\",\n" + " \"description\": \"Hack!!\",\n" + " \"location\": \"Northeastern University, Huntington Avenue, Boston, MA, United States\",\n" + " \"creator\": {\n" + " \"email\": \"vrohitrao@gmail.com\",\n" + " \"displayName\": \"Rohith Vallu\"\n" + " },\n" + " \"organizer\": {\n" + " \"email\": \"3tor7ojfqihejcj67n9l4t8g2c@group.calendar.google.com\",\n" + " \"displayName\": \"PushEvents\",\n" + " \"self\": true\n" + " },\n" + " \"start\": {\n" + " \"dateTime\": \"2014-03-30T04:30:00+05:30\"\n" + " },\n" + " \"end\": {\n" + " \"dateTime\": \"2014-03-30T19:30:00+05:30\"\n" + " },\n" + " \"visibility\": \"public\",\n" + " \"iCalUID\": \"jgpue3stuo3js5qlsodob84voo@google.com\",\n" + " \"sequence\": 0\n" + " }\n" + " ]\n" + "}"; Gson gson = new Gson(); try { JSONObject jsonData = new JSONObject(jsonString); JSONArray jsonArray = jsonData.getJSONArray("items"); JSONObject eventData; Event event = new Event(); for (int i = 0; i < jsonArray.length(); i++) { System.out.println(jsonArray.get(i).toString()); Items item = gson.fromJson(jsonArray.get(i).toString(), Items.class); event.setSummary(item.getSummary()); event.setLocation(item.getLocation()); /* Will be adding the attendees here ArrayList<EventAttendee> attendees = new ArrayList<EventAttendee>(); attendees.add(new EventAttendee().setEmail("attendeeEmail")); // ... event.setAttendees(attendees); */ Date startDate = new Date(); Date endDate = new Date(startDate.getTime() + 3600000); DateTime start = new DateTime(startDate, TimeZone.getDefault().getDefault().getTimeZone("UTC")); event.setStart(new EventDateTime().setDateTime(start)); DateTime end = new DateTime(endDate, TimeZone.getTimeZone("UTC")); event.setEnd(new EventDateTime().setDateTime(end)); HttpTransport transport = new NetHttpTransport(); JsonFactory jsonFactory = new JacksonFactory(); Calendar.Builder builder = new Calendar.Builder(transport, jsonFactory, null); String clientID = "937140966210.apps.googleusercontent.com"; String redirectURL = "urn:ietf:wg:oauth:2.0:oob"; String clientSecret = "qMFSb_cadYDG7uh3IDXWiMQY"; ArrayList<String> scope = new ArrayList<String>(); scope.add("https://www.googleapis.com/auth/calendar"); String url = new GoogleAuthorizationCodeRequestUrl(clientID, redirectURL, scope).build(); System.out.println("Go to the following link in your browser:"); System.out.println(url); // Read the authorization code from the standard input stream. BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); System.out.println("What is the authorization code?"); String code = in.readLine(); GoogleTokenResponse response = new GoogleAuthorizationCodeTokenRequest(transport, jsonFactory, clientID, clientSecret, redirectURL, code, redirectURL).execute(); GoogleCredential credential = new GoogleCredential().setFromTokenResponse(response); Calendar service = new Calendar.Builder(transport, jsonFactory, credential).build(); Event createdEvent = service.events().insert(item.getSummary(), event).execute(); System.out.println(createdEvent.getId()); } } catch (Exception e) { e.printStackTrace(); } }