List of usage examples for java.util Calendar getTime
public final Date getTime()
Date
object representing this Calendar
's time value (millisecond offset from the Epoch"). From source file:SpinnerDateStartEndSample.java
public static void main(String args[]) { JFrame frame = new JFrame("JSpinner Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Calendar cal = Calendar.getInstance(); Date now = cal.getTime(); cal.add(Calendar.YEAR, -50);/*from ww w. j ava 2 s . com*/ Date startDate = cal.getTime(); cal.add(Calendar.YEAR, 100); Date endDate = cal.getTime(); SpinnerModel model = new SpinnerDateModel(now, startDate, endDate, Calendar.YEAR); JSpinner spinner1 = new JSpinner(model); JPanel panel1 = new JPanel(new BorderLayout()); panel1.add(spinner1, BorderLayout.CENTER); frame.add(panel1, BorderLayout.SOUTH); frame.setSize(200, 90); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { String DATE_FORMAT = "yyyyMMdd"; SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT); Calendar c1 = Calendar.getInstance(); // today System.out.println("Today is " + sdf.format(c1.getTime())); }
From source file:Main.java
public static void main(String[] argv) throws Exception { SpinnerDateModel dateModel = new SpinnerDateModel(); JSpinner spinner = new JSpinner(dateModel); Calendar calendar = new GregorianCalendar(2000, Calendar.JANUARY, 1); spinner.setValue(calendar.getTime()); }
From source file:MainClass.java
public static void main(String[] args) { StopWatch stWatch = new StopWatch(); //Start StopWatch stWatch.start();/* w w w. j a v a2 s. co m*/ //Get iterator for all days in a week starting Monday Iterator itr = DateUtils.iterator(new Date(), DateUtils.RANGE_WEEK_MONDAY); while (itr.hasNext()) { Calendar gCal = (Calendar) itr.next(); System.out.println(gCal.getTime()); } //Stop StopWatch stWatch.stop(); System.out.println("Time Taken >>" + stWatch.getTime()); }
From source file:Main.java
public static void main(String[] args) { Date date = Date.valueOf("2015-12-25"); System.out.println(date);/* w ww . j ava 2 s . c om*/ Calendar cal = new GregorianCalendar(); cal.setTime(date); System.out.println(cal.getTime()); }
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()); }
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(); cal.add(Calendar.YEAR, -50);//from www . j a va2 s . c o m 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:DateAddHour.java
public static void main(String[] args) { Calendar calendar = Calendar.getInstance(); System.out.println("Original = " + calendar.getTime()); // Substract 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()); }
From source file:Main.java
public static void main(String[] args) { Date d1 = Calendar.getInstance().getTime(); Calendar cal = Calendar.getInstance(); cal.set(Calendar.YEAR, 2000); Date d2 = cal.getTime(); System.out.println("First Date : " + d1); System.out.println("Second Date : " + d2); System.out.println("Is second date after first ? : " + d2.after(d1)); }
From source file:Main.java
public static void main(String[] args) { Calendar now = Calendar.getInstance(); System.out.println(now.getTime()); int dayOfWeek = now.get(Calendar.DAY_OF_WEEK); if (Calendar.SUNDAY == dayOfWeek) { System.out.println("SUNDAY"); }//from w ww .j av a2s. c o m if (Calendar.MONDAY == dayOfWeek) { System.out.println("MONDAY"); } if (Calendar.TUESDAY == dayOfWeek) { System.out.println("TUESDAY"); } if (Calendar.WEDNESDAY == dayOfWeek) { System.out.println("WEDNESDAY"); } if (Calendar.THURSDAY == dayOfWeek) { System.out.println("THURSDAY"); } if (Calendar.FRIDAY == dayOfWeek) { System.out.println("FRIDAY"); } if (Calendar.SATURDAY == dayOfWeek) { System.out.println("SATURDAY"); } }