List of usage examples for java.util Calendar add
public abstract void add(int field, int amount);
From source file:MainClass.java
public static void main(final String args[]) { JFrame frame = new JFrame("JSpinner Dates"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Calendar cal = Calendar.getInstance(); Date now = cal.getTime();//from w w w .j a v a 2s . co m cal.add(Calendar.YEAR, -50); Date startDate = cal.getTime(); cal.add(Calendar.YEAR, 100); Date endDate = cal.getTime(); SpinnerModel model2 = new SpinnerDateModel(now, startDate, endDate, Calendar.YEAR); JSpinner spinner2 = new JSpinner(model2); JLabel label2 = new JLabel("Range"); JPanel panel2 = new JPanel(new BorderLayout()); panel2.add(label2, BorderLayout.WEST); panel2.add(spinner2, BorderLayout.CENTER); frame.add(panel2, BorderLayout.SOUTH); frame.setSize(200, 90); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { Calendar cal = Calendar.getInstance(); System.out.println("Now : " + cal.getTime()); int monthsToDecrement = -1; cal.add(Calendar.MONTH, monthsToDecrement); System.out.println("Date after decrement: " + cal.getTime()); }
From source file:Main.java
public static void main(String[] args) { Calendar cal = Calendar.getInstance(); System.out.println("Now : " + cal.getTime()); int daysToIncrement = 5; cal.add(Calendar.DATE, daysToIncrement); System.out.println("Date after increment: " + cal.getTime()); }
From source file:Main.java
public static void main(String[] args) { Calendar cal = Calendar.getInstance(); System.out.println("Today : " + cal.getTime()); // Subtract 1 year from the calendar cal.add(Calendar.YEAR, -1); System.out.println("1 year ago: " + cal.getTime()); }
From source file:Main.java
public static void main(String[] args) { Calendar cal = Calendar.getInstance(); System.out.println("Today : " + cal.getTime()); // Substract 1 year from the calendar cal.add(Calendar.YEAR, -1); System.out.println("1 year ago: " + cal.getTime()); }
From source file:MainClass.java
public static void main(String argv[]) throws Exception { Calendar cc1 = Calendar.getInstance(); Calendar cc2 = Calendar.getInstance(); cc1.add(Calendar.DAY_OF_MONTH, 10); DateDiff(cc1.getTime(), cc2.getTime()); java.util.Date d1 = makeDate("10/10/2000"); java.util.Date d2 = makeDate("10/18/2000"); DateDiff(d1, d2);// w ww . j a v a2 s .co m java.util.Date d3 = makeDate("1/1/2000"); java.util.Date d4 = makeDate("12/31/2000"); int diff34 = diff(d3, d4); System.out.println("diff34=" + diff34); }
From source file:Main.java
public static void main(String[] args) { Calendar cal = Calendar.getInstance(); System.out.println("Today : " + cal.getTime()); // Subtract 30 days from the calendar cal.add(Calendar.DATE, -30); System.out.println("30 days ago: " + cal.getTime()); }
From source file:Main.java
public static void main(String[] args) { Calendar cal = Calendar.getInstance(); System.out.println("Today : " + cal.getTime()); // Substract 30 days from the calendar cal.add(Calendar.DATE, -30); System.out.println("30 days ago: " + cal.getTime()); }
From source file:com.isoftstone.proxy.Program.java
public static void main(String[] args) throws IOException { int insertIntervalTime = Integer.valueOf(Config.getValue("proxy_insert_minutes")); int checkIntervalTime = Integer.valueOf(Config.getValue("proxy_check_minute")); SchedulerFactory sf = new StdSchedulerFactory(); Scheduler sched;/* w ww . java 2s. c o m*/ try { sched = sf.getScheduler(); // ???? JobDetail parseProxyJob = JobBuilder.newJob(ParseProxyJob.class).withIdentity("parseProxyJob", "Group") .build(); SimpleTrigger parseProxyTrigger = (SimpleTrigger) TriggerBuilder .newTrigger().withIdentity("parseProxyJob", "Group").withSchedule(SimpleScheduleBuilder .simpleSchedule().withIntervalInMinutes(insertIntervalTime).repeatForever()) .startAt(new Date()).build(); sched.scheduleJob(parseProxyJob, parseProxyTrigger); // ?? JobDetail checkProxyJob = JobBuilder.newJob(CheckProxyJob.class).withIdentity("checkProxyJob", "Group") .build(); /** * 10s?. */ Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.SECOND, 10); SimpleTrigger checkProxyTrigger = (SimpleTrigger) TriggerBuilder.newTrigger() .withIdentity("checkProxyJob", "Group").withSchedule(SimpleScheduleBuilder.simpleSchedule() .withIntervalInMinutes(checkIntervalTime).repeatForever()) .startAt(calendar.getTime()).build(); sched.scheduleJob(checkProxyJob, checkProxyTrigger); sched.start(); String uriHost = Config.getValue("http_server_host"); URI baseUri = UriBuilder.fromUri(uriHost).port(9998).build(); ResourceConfig config = new ResourceConfig(HttpProxyServer.class); HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, config); } catch (SchedulerException e) { LOG.error("SchedulerException", e); } }
From source file:DateAddHour.java
public static void main(String[] args) { Calendar calendar = Calendar.getInstance(); System.out.println("Original = " + calendar.getTime()); // Subtract 2 hour from the current time calendar.add(Calendar.HOUR, -2); // Add 30 minutes to the calendar time calendar.add(Calendar.MINUTE, 30); // Add 300 seconds to the calendar time calendar.add(Calendar.SECOND, 300); System.out.println("Updated = " + calendar.getTime()); }