List of usage examples for java.util Date Date
public Date()
From source file:DateDiff.java
public static void main(String[] av) { /** The date at the end of the last century */ Date d1 = new GregorianCalendar(2000, 11, 31, 23, 59).getTime(); /** Today's date */ Date today = new Date(); // Get msec from each, and subtract. long diff = today.getTime() - d1.getTime(); System.out.println(/*w ww . ja v a 2s. com*/ "The 21st century (up to " + today + ") is " + (diff / (1000 * 60 * 60 * 24)) + " days old."); }
From source file:Main.java
public static void main(String[] argv) throws Exception { Locale locale = Locale.FRENCH; // Format with a custom format DateFormat formatter = new SimpleDateFormat("E, dd MMM yyyy", locale); String s = formatter.format(new Date()); }
From source file:MyTimerTask.java
public static void main(String[] args) { TimerTask tasknew = new MyTimerTask(); Timer timer = new Timer(); timer.scheduleAtFixedRate(tasknew, new Date(), 1000); }
From source file:Main.java
public static void main(String[] args) throws InterruptedException { Date date = new Date(); Thread.sleep(1);//from ww w.j a va2 s . c om Date other = new Date(); out.printf("equals? = %s, hashCode? = %s %n", (date.equals(other)), (date.hashCode() == other.hashCode())); Date todayeOne = trim(date); Date todayTwo = trim(other); out.printf("equals? = %s, hashCode? = %s %n", (todayeOne.equals(todayTwo)), (todayeOne.hashCode() == todayTwo.hashCode())); }
From source file:MainClass.java
public static void main(String[] args) { String data;//from w w w . j a v a 2 s . c o m String msg; Hashtable h = new Hashtable(20); System.out.println(h.put("one", new Integer(1))); System.out.println(h.put("name", "A")); System.out.println(h.put("date", new Date())); System.out.println(h.put("one", new Integer(4))); Enumeration e = h.keys(); while (e.hasMoreElements()) System.out.println(e.nextElement()); e = h.elements(); while (e.hasMoreElements()) System.out.println(e.nextElement()); }
From source file:Main.java
public static void main(String[] args) { TimerTask task = new Main(); Timer timer = new Timer(); timer.scheduleAtFixedRate(task, new Date(), 1000); }
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 w w .j av a 2 s. c o m }); timer.start(); JOptionPane.showMessageDialog(null, timeLabel); } }); }
From source file:MyTimerTask.java
public static void main(String[] args) { TimerTask task = new MyTimerTask(); Timer timer = new Timer(); // scheduling the task timer.scheduleAtFixedRate(task, new Date(), 1000); // cancelling the task System.out.println("cancelling task: " + task.cancel()); }
From source file:Main.java
public static void main(String[] args) throws java.text.ParseException { SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); out.println(isBeforeMonths(-1, sdf.parse("14/12/2015"))); out.println(isBeforeMonths(1, new Date())); out.println(isBeforeMonths(-1, sdf.parse("24/12/2015"))); }
From source file:ObjectWriter.java
public static void main(String[] arguments) { Message mess = new Message(); String author = "London"; String recipient = "G, B"; String[] letter = { "Merry Christmas." }; Date now = new Date(); mess.writeMessage(author, recipient, now, letter); try {// w w w . j av a2s . c o m FileOutputStream fo = new FileOutputStream("Message.obj"); ObjectOutputStream oo = new ObjectOutputStream(fo); oo.writeObject(mess); oo.close(); System.out.println("Object created successfully."); } catch (IOException e) { System.out.println("Error - " + e.toString()); } }