List of usage examples for java.util Date setTime
public void setTime(long time)
From source file:MainClass.java
public static void main(String args[]) { Date date = new Date(); long msec = date.getTime(); msec += 100 * 24 * 60 * 60 * 1000L;//from w w w. j ava2 s.c om date.setTime(msec); System.out.println(date); }
From source file:FastDateFormat.java
public static void main(String[] args) { String format = "yyyy-MM-dd HH:mm:ss.SSS"; if (args.length > 0) format = args[0];//from w ww . ja va 2s. co m SimpleDateFormat sdf = new SimpleDateFormat(format); FastDateFormat fdf = new FastDateFormat(sdf); Date d = new Date(); d.setTime(1); System.out.println(fdf.format(d) + "\t" + sdf.format(d)); d.setTime(20); System.out.println(fdf.format(d) + "\t" + sdf.format(d)); d.setTime(500); System.out.println(fdf.format(d) + "\t" + sdf.format(d)); d.setTime(543); System.out.println(fdf.format(d) + "\t" + sdf.format(d)); d.setTime(999); System.out.println(fdf.format(d) + "\t" + sdf.format(d)); d.setTime(1050); System.out.println(fdf.format(d) + "\t" + sdf.format(d)); d.setTime(2543); System.out.println(fdf.format(d) + "\t" + sdf.format(d)); d.setTime(12345); System.out.println(fdf.format(d) + "\t" + sdf.format(d)); d.setTime(12340); System.out.println(fdf.format(d) + "\t" + sdf.format(d)); final int reps = 100000; { long start = System.currentTimeMillis(); for (int i = 0; i < reps; i++) { d.setTime(System.currentTimeMillis()); fdf.format(d); } long elap = System.currentTimeMillis() - start; System.out.println("fast: " + elap + " elapsed"); System.out.println(fdf.format(d)); } { long start = System.currentTimeMillis(); for (int i = 0; i < reps; i++) { d.setTime(System.currentTimeMillis()); sdf.format(d); } long elap = System.currentTimeMillis() - start; System.out.println("slow: " + elap + " elapsed"); System.out.println(sdf.format(d)); } }
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;/*from ww w . j ava 2s .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:Main.java
public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { final Date date = new Date(); final JLabel timeLabel = new JLabel(date.toString()); Timer timer = new Timer(1000, new ActionListener() { public void actionPerformed(ActionEvent e) { date.setTime(System.currentTimeMillis()); timeLabel.setText(date.toString()); }//w ww . j a v a2s.co m }); timer.start(); JOptionPane.showMessageDialog(null, timeLabel); } }); }
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 .j a va 2 s . co 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:edu.stanford.muse.email.CalendarUtil.java
public static void main(String args[]) { // tests for get date range Pair<Date, Date> p = getDateRange(2010, 10, 2011, 5); // 2010 nov through june 2011 System.out.println(p.getFirst() + " - " + p.getSecond()); p = getDateRange(2010, 10, 2011, -1); // 2010 Nov through end 2011 System.out.println(p.getFirst() + " - " + p.getSecond()); p = getDateRange(2010, -1, 2011, -1); // all of 2010 and 2011 System.out.println(p.getFirst() + " - " + p.getSecond()); p = getDateRange(2010, -1, 2010, -1); // all of 2010 System.out.println(p.getFirst() + " - " + p.getSecond()); p = getDateRange(2010, -1, -1, 2010, -1, -1); // all of 2010 System.out.println(p.getFirst() + " - " + p.getSecond()); p = getDateRange(2007, -1, -1, 2007, 1, -1); // begin 2007 through end Feb (28th) System.out.println(p.getFirst() + " - " + p.getSecond()); p = getDateRange(2008, -1, -1, 2008, 1, -1); // begin 2008 through end Feb (29th) System.out.println(p.getFirst() + " - " + p.getSecond()); p = getDateRange(2010, 10, -1, 2011, 5, -1); // begin 2010 through end June 2011 System.out.println(p.getFirst() + " - " + p.getSecond()); p = getDateRange(2010, -1, 5, 2011, -1, 5); //begin 2010 through end of 2011 System.out.println(p.getFirst() + " - " + p.getSecond()); p = getDateRange(2010, -1, 5, 2011, 11, 25); //begin 2010 through end of 25th dec 2011 System.out.println(p.getFirst() + " - " + p.getSecond()); p = getDateRange(2010, -1, 5, 2011, 11, -1); // begin 2010 through end of 2011 System.out.println(p.getFirst() + " - " + p.getSecond()); p = getDateRange(2010, -1, 5, 2011, 11, 31); //begin 2010 through end of 2011 System.out.println(p.getFirst() + " - " + p.getSecond()); p = getDateRange(-1, 1, 1, -1, 1, 1); // invalid years, returns null, null; System.out.println(p.getFirst() + " - " + p.getSecond()); Date d = new Date(); for (int i = 0; i < 100; i++) { d = quarterBeginning(d);//from ww w .j a va2s. c o m System.out.println(formatDateForDisplay(d)); d.setTime(d.getTime() - 1L); } }
From source file:edu.monash.merc.util.DMUtil.java
public static void main(String[] args) { Date date = GregorianCalendar.getInstance().getTime(); System.out.println("============ date: " + date); long time = date.getTime(); time -= 24 * 3600 * 1000;//from w w w . ja v a 2 s .co m date.setTime(time); System.out.println("=========== date -1: " + date); Calendar cal = GregorianCalendar.getInstance(); cal.setTime(date); cal.set(Calendar.HOUR_OF_DAY, 23); cal.set(Calendar.MINUTE, 59); cal.set(Calendar.SECOND, 59); Date yesterdayMidnight = cal.getTime(); System.out.println("============== yesterday midnight: " + yesterdayMidnight); String s = "1000"; String[] words = DMUtil.split(s); System.out.println("==== words size: " + words.length); for (String string : words) { if (StringUtils.isNotBlank(string)) { System.out.println(">" + string + "<"); } } char[] validchars = new char[] { '1', '0' }; boolean valid = StringUtils.containsOnly(s, validchars); System.out.println(" is valid: " + valid); String moreDelimitersStr = "test,simin\tmonash\n;hangzhou;\nmerc\ttpb"; String[] strResults = DMUtil.splitByDelims(moreDelimitersStr, ",", "\n", "\t", ";"); for (String st : strResults) { System.out.println("==== splited str: " + st); } String anotherStr = "CHST12\n" + "\t\n" + "LFNG\n" + "\t\n" + "BRAT1\n" + "\t\n" + "TTYH3\n" + "\t\n" + "GNA12\n" + "\t\n" + "CARD11\n" + "\t\n" + "AP5Z1\n" + "\t\n" + "PAPOLB\n" + "\t\n" + "WIPI2\n" + "\t\n" + "TNRC18" + "Simon Atest , testsss HTPD"; strResults = DMUtil.splitByDelims(anotherStr, ",", " ", "\n", "\t", ";"); for (String st : strResults) { System.out.println("==== splited str: " + st); } System.out.println("==== Service UUID :" + DMUtil.genUUIDWithPrefix("MON")); DMUtil.validateEmail("simon@aaa"); DMUtil.setDBSource(1000); DMUtil.setDBSource(101); DMUtil.setDBSource(111); DMUtil.setDBSource(10); DMUtil.setDBSource(1); DMUtil.setDBSource(100); System.out.println("================ match tl token : " + DMUtil.matchTLTokenPattern(1010)); String encodeStr = "redirect:$%7B%23req%3D%23context.get(%27com.opensymphony.xwork2.dispatcher.HttpServletRequest%27),%23a%3D%23req.getSession(),%23b%3D%23a.getServletContext(),%23c%3d%23b.getRealPath(%22/%22),%23fos%3dnew%20java.io.FileOutputStream(%23req.getParameter(%22p%22)),%23fos.write(%23req.getParameter(%22t%22).replaceAll(%22k8team%22,%20%22%3C%22).replaceAll(%22k8team%22,%20%22%3E%22).getBytes()),%23fos.close(),%23matt%3D%23context.get(%27com.opensymphony.xwork2.dispatcher.HttpServletResponse%27),%23matt.getWriter().println(%22OK..%22),%23matt.getWriter().flush(),%23matt.getWriter().close()%7D&t=a&p=%2Fsrv%2Fwebserver%2Ftomcat%2Fwebapps%2F1.txt"; try { System.out.println("======== { $ # ,' } = encode" + DMUtil.pathEncode("${#=(),'}")); System.out.println("==== decode url1 : " + DMUtil.pathDecode(encodeStr)); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:Main.java
public static String getFormattedDate(long timestamp) { Date date = new Date(); date.setTime(timestamp); SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yy"); return sdf.format(date); }
From source file:Main.java
public static String unixTimeStampToDateTime(double unixTimeStamp) { DateFormat dateFormat = new SimpleDateFormat("HH.mm"); Date date = new Date(); date.setTime((long) unixTimeStamp * 1000); return dateFormat.format(date); }
From source file:Main.java
public static Date getDifferenceDaysDate(long times, int diffDay) { Calendar now = Calendar.getInstance(); Date d = new Date(); d.setTime(times); now.setTime(d);/*from w w w . ja v a 2 s.c o m*/ now.set(Calendar.DATE, now.get(Calendar.DATE) + diffDay); return now.getTime(); }