List of usage examples for java.util Date getTime
public long getTime()
From source file:KVMCalendar.java
public static void main(String[] args) { Calendar cal = Calendar.getInstance(); Date date = new Date(); cal.setTime(date);//from w w w. ja v a2 s . c o m int month = cal.get(Calendar.MONTH); int day = cal.get(Calendar.DAY_OF_MONTH); System.out.println("Day is " + day + ", month is " + month); final long MILLIS_PER_DAY = 24 * 60 * 60 * 1000L; long offset = date.getTime(); offset += 20 * MILLIS_PER_DAY; date.setTime(offset); cal.setTime(date); month = cal.get(Calendar.MONTH); day = cal.get(Calendar.DAY_OF_MONTH); System.out.println("In 20 days time, day will " + day + ", month will be " + month); System.out.println(cal); }
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 ww . j a v a 2s. c o m 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); dbConnection.setAutoCommit(false); java.util.Date today = new java.util.Date(); preparedStatement.setInt(1, 101); preparedStatement.setString(2, "101"); preparedStatement.setString(3, "system"); preparedStatement.setTimestamp(4, new java.sql.Timestamp(today.getTime())); preparedStatement.addBatch(); preparedStatement.setInt(1, 102); preparedStatement.setString(2, "102"); preparedStatement.setString(3, "system"); preparedStatement.setTimestamp(4, new java.sql.Timestamp(today.getTime())); preparedStatement.addBatch(); preparedStatement.setInt(1, 103); preparedStatement.setString(2, "103"); preparedStatement.setString(3, "system"); preparedStatement.setTimestamp(4, new java.sql.Timestamp(today.getTime())); preparedStatement.addBatch(); preparedStatement.executeBatch(); dbConnection.commit(); preparedStatement.close(); dbConnection.close(); }
From source file:Main.java
/** Index all text files under a directory. */ public static void main(String[] args) { String usage = "java IndexFiles" + " [-index INDEX_PATH] [-docs DOCS_PATH] [-update]\n\n" + "This indexes the documents in DOCS_PATH, creating a Lucene index" + "in INDEX_PATH that can be searched with SearchFiles"; String indexPath = "index"; String docsPath = null;/*from ww w .j a v a 2s . c o m*/ boolean create = true; for (int i = 0; i < args.length; i++) { if ("-index".equals(args[i])) { indexPath = args[i + 1]; i++; } else if ("-docs".equals(args[i])) { docsPath = args[i + 1]; i++; } else if ("-update".equals(args[i])) { create = false; } } if (docsPath == null) { System.err.println("Usage: " + usage); System.exit(1); } final File docDir = new File(docsPath); if (!docDir.exists() || !docDir.canRead()) { System.out.println("Document directory '" + docDir.getAbsolutePath() + "' does not exist or is not readable, please check the path"); System.exit(1); } Date start = new Date(); try { System.out.println("Indexing to directory '" + indexPath + "'..."); Directory dir = FSDirectory.open(new File(indexPath)); // :Post-Release-Update-Version.LUCENE_XY: Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_4_10_0); IndexWriterConfig iwc = new IndexWriterConfig(Version.LUCENE_4_10_0, analyzer); if (create) { // Create a new index in the directory, removing any // previously indexed documents: iwc.setOpenMode(OpenMode.CREATE); } else { // Add new documents to an existing index: iwc.setOpenMode(OpenMode.CREATE_OR_APPEND); } // Optional: for better indexing performance, if you // are indexing many documents, increase the RAM // buffer. But if you do this, increase the max heap // size to the JVM (eg add -Xmx512m or -Xmx1g): // // iwc.setRAMBufferSizeMB(256.0); IndexWriter writer = new IndexWriter(dir, iwc); indexDocs(writer, docDir); // NOTE: if you want to maximize search performance, // you can optionally call forceMerge here. This can be // a terribly costly operation, so generally it's only // worth it when your index is relatively static (ie // you're done adding documents to it): // // writer.forceMerge(1); writer.close(); Date end = new Date(); System.out.println(end.getTime() - start.getTime() + " total milliseconds"); } catch (IOException e) { System.out.println(" caught a " + e.getClass() + "\n with message: " + e.getMessage()); } }
From source file:edu.uga.cs.fluxbuster.FluxbusterCLI.java
/** * The main method./* w w w.j a v a 2 s . c om*/ * * @param args the command line arguments */ public static void main(String[] args) { GnuParser parser = new GnuParser(); Options opts = FluxbusterCLI.initializeOptions(); CommandLine cli; try { cli = parser.parse(opts, args); if (cli.hasOption('?')) { throw new ParseException(null); } if (validateDate(cli.getOptionValue('d')) && validateDate(cli.getOptionValue('e'))) { if (log.isInfoEnabled()) { StringBuffer arginfo = new StringBuffer("\n"); arginfo.append("generate-clusters: " + cli.hasOption('g') + "\n"); arginfo.append("calc-features: " + cli.hasOption('f') + "\n"); arginfo.append("calc-similarity: " + cli.hasOption('s') + "\n"); arginfo.append("classify-clusters: " + cli.hasOption('c') + "\n"); arginfo.append("start-date: " + cli.getOptionValue('d') + "\n"); arginfo.append("end-date: " + cli.getOptionValue('e') + "\n"); log.info(arginfo.toString()); } try { boolean clus = true, feat = true, simil = true, clas = true; if (cli.hasOption('g') || cli.hasOption('f') || cli.hasOption('s') || cli.hasOption('c')) { if (!cli.hasOption('g')) { clus = false; } if (!cli.hasOption('f')) { feat = false; } if (!cli.hasOption('s')) { simil = false; } if (!cli.hasOption('c')) { clas = false; } } DBInterfaceFactory.init(); SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd"); Date logdate = df.parse(cli.getOptionValue('d')); long startTime = logdate.getTime() / 1000; long endTime = df.parse(cli.getOptionValue('e')).getTime() / 1000; if (clus) { ClusterGenerator cg = new ClusterGenerator(); List<DomainCluster> clusters = cg.generateClusters(startTime, endTime, true); cg.storeClusters(clusters, logdate); } if (feat) { FeatureCalculator calc = new FeatureCalculator(); calc.updateFeatures(logdate); } if (simil) { ClusterSimilarityCalculator calc2 = new ClusterSimilarityCalculator(); calc2.updateClusterSimilarities(logdate); } if (clas) { Classifier calc3 = new Classifier(); calc3.updateClusterClasses(logdate, 30); } } catch (Exception e) { if (log.isFatalEnabled()) { log.fatal("", e); } } finally { DBInterfaceFactory.shutdown(); } } else { throw new ParseException(null); } } catch (ParseException e1) { PrintWriter writer = new PrintWriter(System.out); HelpFormatter usageFormatter = new HelpFormatter(); usageFormatter.printHelp(writer, 80, "fluxbuster", "If none of the options g, f, s, c are specified " + "then the program will execute as if all of them " + "have been specified. Otherwise, the program will " + "only execute the options specified.", opts, 0, 2, ""); writer.close(); } }
From source file:Main.java
public static void main(String[] argv) throws Exception { Class.forName(DB_DRIVER);//from w ww . ja v a2s. co m Connection dbConnection = DriverManager.getConnection(DB_CONNECTION, DB_USER, DB_PASSWORD); CallableStatement callableStatement = null; String insertStoreProc = "{call insertPERSON(?,?,?,?)}"; java.util.Date today = new java.util.Date(); callableStatement = dbConnection.prepareCall(insertStoreProc); callableStatement.setInt(1, 1000); callableStatement.setString(2, "name"); callableStatement.setString(3, "system"); callableStatement.setDate(4, new java.sql.Date(today.getTime())); callableStatement.executeUpdate(); System.out.println("Record is inserted into PERSON table!"); callableStatement.close(); dbConnection.close(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { Class.forName(DB_DRIVER);// w w w. j av a2s . co m Connection dbConnection = DriverManager.getConnection(DB_CONNECTION, DB_USER, DB_PASSWORD); PreparedStatement preparedStatement = null; java.util.Date today = new java.util.Date(); String insertTableSQL = "INSERT INTO DBUSER" + "(USER_ID, USERNAME, CREATED_BY, CREATED_DATE) VALUES" + "(?,?,?,?)"; preparedStatement = dbConnection.prepareStatement(insertTableSQL); preparedStatement.setTimestamp(4, new java.sql.Timestamp(today.getTime())); dbConnection.commit(); dbConnection.close(); }
From source file:com.mvdb.etl.actions.ModifyCustomerData.java
public static void main(String[] args) { ActionUtils.assertEnvironmentSetupOk(); ActionUtils.assertFileExists("~/.mvdb", "~/.mvdb missing. Existing."); ActionUtils.assertFileExists("~/.mvdb/status.InitCustomerData.complete", "300init-customer-data.sh not executed yet. Exiting"); //This check is not required as data can be modified any number of times //ActionUtils.assertFileDoesNotExist("~/.mvdb/status.ModifyCustomerData.complete", "ModifyCustomerData already done. Start with 100init.sh if required. Exiting"); ActionUtils.setUpInitFileProperty(); ActionUtils.createMarkerFile("~/.mvdb/status.ModifyCustomerData.start", true); String customerName = null;// ww w . j av a 2 s.c om //Date startDate = null; //Date endDate = null; final CommandLineParser cmdLinePosixParser = new PosixParser(); final Options posixOptions = constructPosixOptions(); CommandLine commandLine; try { commandLine = cmdLinePosixParser.parse(posixOptions, args); // if (commandLine.hasOption("startDate")) // { // String startDateStr = commandLine.getOptionValue("startDate"); // startDate = ActionUtils.getDate(startDateStr); // } // if (commandLine.hasOption("endDate")) // { // String endDateStr = commandLine.getOptionValue("endDate"); // endDate = ActionUtils.getDate(endDateStr); // } if (commandLine.hasOption("customerName")) { customerName = commandLine.getOptionValue("customerName"); } } catch (ParseException parseException) // checked exception { System.err.println( "Encountered exception while parsing using PosixParser:\n" + parseException.getMessage()); } if (customerName == null) { System.err.println("customerName has not been specified. Aborting..."); System.exit(1); } // if (startDate == null) // { // System.err.println("startDate has not been specified with the correct format YYYYMMddHHmmss. Aborting..."); // System.exit(1); // } // // if (endDate == null) // { // System.err.println("endDate has not been specified with the correct format YYYYMMddHHmmss. Aborting..."); // System.exit(1); // } // // if (endDate.after(startDate) == false) // { // System.err.println("endDate must be after startDate. Aborting..."); // System.exit(1); // } ApplicationContext context = Top.getContext(); final OrderDAO orderDAO = (OrderDAO) context.getBean("orderDAO"); long maxId = orderDAO.findMaxId(); long totalOrders = orderDAO.findTotalOrders(); long modifyCount = (long) (totalOrders * 0.1); String lastUsedEndTimeStr = ActionUtils.getConfigurationValue(customerName, ConfigurationKeys.LAST_USED_END_TIME); long lastUsedEndTime = Long.parseLong(lastUsedEndTimeStr); Date startDate1 = new Date(); startDate1.setTime(lastUsedEndTime + 1000 * 60 * 60 * 24 * 1); Date endDate1 = new Date(startDate1.getTime() + 1000 * 60 * 60 * 24 * 1); for (int i = 0; i < modifyCount; i++) { Date updateDate = RandomUtil.getRandomDateInRange(startDate1, endDate1); long orderId = (long) Math.floor((Math.random() * maxId)) + 1L; logger.info("Modify Id " + orderId + " in orders"); Order theOrder = orderDAO.findByOrderId(orderId); // System.out.println("theOrder : " + theOrder); theOrder.setNote(RandomUtil.getRandomString(4)); theOrder.setUpdateTime(updateDate); theOrder.setSaleCode(RandomUtil.getRandomInt()); orderDAO.update(theOrder); // System.out.println("theOrder Modified: " + theOrder); } ActionUtils.setConfigurationValue(customerName, ConfigurationKeys.LAST_USED_END_TIME, String.valueOf(endDate1.getTime())); logger.info("Modified " + modifyCount + " orders"); ActionUtils.createMarkerFile("~/.mvdb/status.ModifyCustomerData.complete", true); }
From source file:ci6226.buildindex.java
/** * @param args the command line arguments *//*from ww w . ja va 2 s . c o m*/ public static void main(String[] args) throws FileNotFoundException, IOException, ParseException { String file = "/home/steven/Dropbox/workspace/ntu_coursework/ci6226/Assiment/yelpdata/yelp_training_set/yelp_training_set_review.json"; JSONParser parser = new JSONParser(); BufferedReader in = new BufferedReader(new FileReader(file)); // List<Document> jdocs = new LinkedList<Document>(); Date start = new Date(); String indexPath = "./myindex"; System.out.println("Indexing to directory '" + indexPath + "'..."); // Analyzer analyzer= new NGramAnalyzer(2,8); Analyzer analyzer = new myAnalyzer(); IndexWriterConfig iwc = new IndexWriterConfig(Version.LUCENE_47, analyzer); Directory dir = FSDirectory.open(new File(indexPath)); // :Post-Release-Update-Version.LUCENE_XY: // TODO: try different analyzer,stop words,words steming check size // Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_47); // Add new documents to an existing index: // iwc.setOpenMode(OpenMode.CREATE_OR_APPEND); iwc.setOpenMode(OpenMode.CREATE_OR_APPEND); // Optional: for better indexing performance, if you // are indexing many documents, increase the RAM // buffer. But if you do this, increase the max heap // size to the JVM (eg add -Xmx512m or -Xmx1g): // // iwc.setRAMBufferSizeMB(256.0); IndexWriter writer = new IndexWriter(dir, iwc); // writer.addDocuments(jdocs); int line = 0; while (in.ready()) { String s = in.readLine(); Object obj = JSONValue.parse(s); JSONObject person = (JSONObject) obj; String text = (String) person.get("text"); String user_id = (String) person.get("user_id"); String business_id = (String) person.get("business_id"); String review_id = (String) person.get("review_id"); JSONObject votes = (JSONObject) person.get("votes"); long funny = (Long) votes.get("funny"); long cool = (Long) votes.get("cool"); long useful = (Long) votes.get("useful"); Document doc = new Document(); Field review_idf = new StringField("review_id", review_id, Field.Store.YES); doc.add(review_idf); Field business_idf = new StringField("business_id", business_id, Field.Store.YES); doc.add(business_idf); //http://qindongliang1922.iteye.com/blog/2030639 FieldType ft = new FieldType(); ft.setIndexed(true);// ft.setStored(true);// ft.setStoreTermVectors(true); ft.setTokenized(true); ft.setStoreTermVectorPositions(true);//? ft.setStoreTermVectorOffsets(true);//??? Field textf = new Field("text", text, ft); doc.add(textf); // Field user_idf = new StringField("user_id", user_id, Field.Store.YES); // doc.add(user_idf); // doc.add(new LongField("cool", cool, Field.Store.YES)); // doc.add(new LongField("funny", funny, Field.Store.YES)); // doc.add(new LongField("useful", useful, Field.Store.YES)); writer.addDocument(doc); System.out.println(line++); } writer.close(); Date end = new Date(); System.out.println(end.getTime() - start.getTime() + " total milliseconds"); // BufferedReader in = new BufferedReader(new FileReader(file)); //while (in.ready()) { // String s = in.readLine(); // //System.out.println(s); // JSONObject jsonObject = (JSONObject) ((Object)s); // String rtext = (String) jsonObject.get("text"); // System.out.println(rtext); // //long age = (Long) jsonObject.get("age"); // //System.out.println(age); //} //in.close(); }
From source file:Main.java
/** Simple command-line based search demo. */ public static void main(String[] args) throws Exception { String usage = "Usage:\tjava SearchFiles [-index dir] [-field f] [-repeat n] [-queries file] [-query string] [-raw] [-paging hitsPerPage]\n\nSee http://lucene.apache.org/core/4_1_0/demo/ for details."; if (args.length > 0 && ("-h".equals(args[0]) || "-help".equals(args[0]))) { System.out.println(usage); System.exit(0);/* w ww . jav a2s .com*/ } String index = "index"; String field = "contents"; String queries = null; int repeat = 0; boolean raw = false; String queryString = null; int hitsPerPage = 10; for (int i = 0; i < args.length; i++) { if ("-index".equals(args[i])) { index = args[i + 1]; i++; } else if ("-field".equals(args[i])) { field = args[i + 1]; i++; } else if ("-queries".equals(args[i])) { queries = args[i + 1]; i++; } else if ("-query".equals(args[i])) { queryString = args[i + 1]; i++; } else if ("-repeat".equals(args[i])) { repeat = Integer.parseInt(args[i + 1]); i++; } else if ("-raw".equals(args[i])) { raw = true; } else if ("-paging".equals(args[i])) { hitsPerPage = Integer.parseInt(args[i + 1]); if (hitsPerPage <= 0) { System.err.println("There must be at least 1 hit per page."); System.exit(1); } i++; } } IndexReader reader = DirectoryReader.open(FSDirectory.open(new File(index))); IndexSearcher searcher = new IndexSearcher(reader); // :Post-Release-Update-Version.LUCENE_XY: Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_4_10_0); BufferedReader in = null; if (queries != null) { in = new BufferedReader(new InputStreamReader(new FileInputStream(queries), StandardCharsets.UTF_8)); } else { in = new BufferedReader(new InputStreamReader(System.in, StandardCharsets.UTF_8)); } // :Post-Release-Update-Version.LUCENE_XY: QueryParser parser = new QueryParser(Version.LUCENE_4_10_0, field, analyzer); while (true) { if (queries == null && queryString == null) { // prompt the user System.out.println("Enter query: "); } String line = queryString != null ? queryString : in.readLine(); if (line == null || line.length() == -1) { break; } line = line.trim(); if (line.length() == 0) { break; } Query query = parser.parse(line); System.out.println("Searching for: " + query.toString(field)); if (repeat > 0) { // repeat & time as benchmark Date start = new Date(); for (int i = 0; i < repeat; i++) { searcher.search(query, null, 100); } Date end = new Date(); System.out.println("Time: " + (end.getTime() - start.getTime()) + "ms"); } doPagingSearch(in, searcher, query, hitsPerPage, raw, queries == null && queryString == null); if (queryString != null) { break; } } reader.close(); }
From source file:edu.psu.citeseerx.disambiguation.CsxDisambiguation.java
public static void main(String[] args) { Date start = new Date(); System.out.println("START:" + start); try {/*w w w . jav a2 s . com*/ CommandLineParser cmdparser = new GnuParser(); Options options = setupOptions(); CommandLine line = cmdparser.parse(options, args); ListableBeanFactory factory = ContextReader.loadContext(); if (!validOptions(line, options)) { usage(options); System.exit(0); } String cmd = line.getOptionValue("cmd"); String infile = line.getOptionValue("infile"); String indir = line.getOptionValue("indir"); String outdir = line.getOptionValue("outdir"); if (cmd.equals("init_dirs")) { // 1) init directories initDirectories("data/csauthors/blocks"); initDirectories("data/csauthors/output"); } else if (cmd.equals("init_blocks")) { // 2) create blocks createBlocks(factory); } else if (cmd.equals("dbscan")) { // 3) disambiguate (required 1. & 2.) //disambiguateDirectory(factory, args[0], args[1]); //disambiguateFile(factory, args[0]); if (infile != null) { disambiguateFile(factory, infile); } else if (indir != null && outdir != null) { disambiguateDirectory(factory, indir, outdir); } else { usage(options); System.exit(0); } } /*else if (cmd.equals("match_author")) { String input_file = ""; disambiguateOneAuthor(input_file); }*/ } catch (Exception ex) { ex.printStackTrace(); Date now = new Date(); System.out.println("CRASH:" + now); } Date end = new Date(); System.out.println("END:" + end); System.out.println("TIME:" + (end.getTime() - start.getTime())); }