List of usage examples for java.util Date Date
public Date()
From source file:Main.java
public static void main(String[] args) { StringBuilder sb = new StringBuilder(); Formatter fm = new Formatter(sb); // Formatting strings fm.format("%1$s, %2$s, and %3$s %n", "A", "B", "C"); fm.format("%3$s, %2$s, and %1$s %n", "D", "E", "F"); // Formatting numbers fm.format("%1$4d, %2$4d, %3$4d %n", 1, 10, 100); fm.format("%1$4d, %2$4d, %3$4d %n", 10, 100, 1000); fm.format("%1$-4d, %2$-4d, %3$-4d %n", 1, 10, 100); fm.format("%1$-4d, %2$-4d, %3$-4d %n", 10, 100, 1000); // Formatting date and time Date dt = new Date(); fm.format("Today is %tD %n", dt); fm.format("Today is %tF %n", dt); fm.format("Today is %tc %n", dt); // Display the entire formatted string System.out.println(sb.toString()); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { Box form = Box.createVerticalBox(); form.add(new JLabel("Name:")); form.add(new JTextField("User Name")); form.add(new JLabel("Birthday:")); JFormattedTextField birthdayField = new JFormattedTextField(new SimpleDateFormat("MM/dd/yy")); birthdayField.setValue(new Date()); form.add(birthdayField);//from w w w . j av a 2 s . c om form.add(new JLabel("Age:")); form.add(new JFormattedTextField(new Integer(32))); form.add(new JLabel("Hairs on Body:")); JFormattedTextField hairsField = new JFormattedTextField(new DecimalFormat("###,###")); hairsField.setValue(new Integer(100000)); form.add(hairsField); form.add(new JLabel("Phone Number:")); JFormattedTextField phoneField = new JFormattedTextField(new MaskFormatter("(###)###-####")); phoneField.setValue("(314)888-1234"); form.add(phoneField); JFrame frame = new JFrame("User Information"); frame.getContentPane().add(form); frame.pack(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); }
From source file:J2METimeServer.java
public static void main(String[] args) { try {/*from www . j av a 2s . co m*/ Calendar cal = Calendar.getInstance(); DatagramConnection receiver = (DatagramConnection) Connector.open("datagram://"); byte[] buffer = new byte[256]; Datagram dgram = receiver.newDatagram(buffer, buffer.length); for (;;) { dgram.setLength(buffer.length); receiver.receive(dgram); cal.setTime(new Date()); String time = cal.toString(); byte[] dataBytes = time.getBytes(); System.arraycopy(dataBytes, 0, buffer, 0, dataBytes.length); dgram.setLength(dataBytes.length); receiver.send(dgram); } } catch (IOException ex) { System.out.println("IOException: " + ex); } }
From source file:Main.java
public static void main(String[] args) throws ParseException { SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy"); String oeStartDateStr = "04/01/2015"; String oeEndDateStr = "11/14/2015"; Calendar cal = Calendar.getInstance(); Integer year = cal.get(Calendar.YEAR); oeStartDateStr = oeStartDateStr.concat(year.toString()); oeEndDateStr = oeEndDateStr.concat(year.toString()); Date startDate = sdf.parse(oeStartDateStr); Date endDate = sdf.parse(oeEndDateStr); Date d = new Date(); String currDt = sdf.format(d); if ((d.after(startDate) && (d.before(endDate))) || (currDt.equals(sdf.format(startDate)) || currDt.equals(sdf.format(endDate)))) { System.out.println("Date is between 1st april to 14th nov..."); } else {//from ww w . ja va2s .c om System.out.println("Date is not between 1st april to 14th nov..."); } }
From source file:MainClass.java
public static void main(String[] args) { Date today = new Date(); Locale[] locales = { Locale.US, Locale.UK, Locale.GERMANY, Locale.FRANCE }; int[] styles = { DateFormat.FULL, DateFormat.LONG, DateFormat.MEDIUM, DateFormat.SHORT }; DateFormat fmt;/* w ww . j av a 2 s. c o m*/ String[] styleText = { "FULL", "LONG", "MEDIUM", "SHORT" }; // Output the date for each local in four styles for (int i = 0; i < locales.length; i++) { System.out.println("\nThe Date for " + locales[i].getDisplayCountry() + ":"); for (int j = 0; j < styles.length; j++) { fmt = DateFormat.getDateInstance(styles[j], locales[i]); System.out.println("\tIn " + styleText[j] + " is " + fmt.format(today)); } } }
From source file:Main.java
public static void main(String args[]) throws IOException, ClassNotFoundException { File file = new File("test.txt"); FileOutputStream outFile = new FileOutputStream(file); ObjectOutputStream outStream = new ObjectOutputStream(outFile); TestClass1 t1 = new TestClass1(true, 9, 'A', 0.0001, "java"); TestClass2 t2 = new TestClass2(); String t3 = "This is a test."; Date t4 = new Date(); outStream.writeObject(t1);//from w w w. j a v a2s. c o m outStream.writeObject(t2); outStream.writeObject(t3); outStream.writeObject(t4); outStream.close(); outFile.close(); FileInputStream inFile = new FileInputStream(file); ObjectInputStream inStream = new ObjectInputStream(inFile); System.out.println(inStream.readObject()); System.out.println(inStream.readObject()); System.out.println(inStream.readObject()); System.out.println(inStream.readObject()); inStream.close(); inFile.close(); file.delete(); }
From source file:EventObject.java
public static void main(String[] args) { JFrame f = new JFrame(); JButton ok = new JButton("Ok"); ok.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(event.getWhen()); Locale locale = Locale.getDefault(); String s = DateFormat.getTimeInstance(DateFormat.SHORT, locale).format(new Date()); if (event.getID() == ActionEvent.ACTION_PERFORMED) System.out.println(" Event Id: ACTION_PERFORMED"); System.out.println(" Time: " + s); String source = event.getSource().getClass().getName(); System.out.println(" Source: " + source); int mod = event.getModifiers(); if ((mod & ActionEvent.ALT_MASK) > 0) System.out.println("Alt "); if ((mod & ActionEvent.SHIFT_MASK) > 0) System.out.println("Shift "); if ((mod & ActionEvent.META_MASK) > 0) System.out.println("Meta "); if ((mod & ActionEvent.CTRL_MASK) > 0) System.out.println("Ctrl "); }/*from www. j a v a2s. c om*/ }); f.add(ok); f.setSize(420, 250); f.setLocationRelativeTo(null); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); }
From source file:util.Main.java
public static void main(String[] args) { ApplicationContext appContext = new ClassPathXmlApplicationContext("applicationContext.xml"); SpecificTAAService genericTAAService = (SpecificTAAService) appContext.getBean("specificTAAService"); SpecificTAA genericTAA = new SpecificTAA(); genericTAA.setApprovedByDos(new Date()); genericTAA.setDraft(new Date()); genericTAA.setFullyExecuted(new Date()); genericTAA.setSubmissionToDoS(new Date()); genericTAA.setLicenseNumber("test2"); genericTAA.setSubject("test2"); genericTAA.setVersionNumber("test2"); genericTAAService.save(genericTAA);/*from w ww. j a va2 s . c om*/ }
From source file:Main.java
public static void main(String[] argv) { DefaultTableModel model = new DefaultTableModel() { public Class getColumnClass(int columnIndex) { Object o = getValueAt(0, columnIndex); if (o == null) { return Object.class; } else { return o.getClass(); }/*from ww w . j a v a2 s. com*/ } }; JTable table = new JTable(model); model.addColumn("Boolean", new Object[] { Boolean.TRUE }); model.addColumn("Date", new Object[] { new Date() }); model.addColumn("Double", new Object[] { new Double(Math.PI) }); model.addColumn("Float", new Object[] { new Float(1.2) }); model.addColumn("Icon", new Object[] { new ImageIcon("icon.gif") }); model.addColumn("Number", new Object[] { new Integer(1) }); model.addColumn("Object", new Object[] { "object" }); JFrame f = new JFrame(); f.setSize(300, 300); f.add(new JScrollPane(table)); f.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) { DefaultTableModel model = new DefaultTableModel() { public Class getColumnClass(int columnIndex) { Object o = getValueAt(0, columnIndex); if (o == null) { return Object.class; } else { return o.getClass(); }// w ww . j a va 2 s. c o m } }; JTable table = new JTable(model); model.addColumn("Boolean", new Object[] { Boolean.TRUE }); model.addColumn("Date", new Object[] { new Date() }); model.addColumn("Double", new Object[] { new Double(Math.PI) }); model.addColumn("Float", new Object[] { new Float(1.2) }); model.addColumn("Icon", new Object[] { new ImageIcon("icon.gif") }); model.addColumn("Number", new Object[] { new Integer(1) }); model.addColumn("Object", new Object[] { "object" }); Enumeration e = table.getColumnModel().getColumns(); TableColumn col = (TableColumn) e.nextElement(); col.setCellRenderer(table.getDefaultRenderer(Boolean.class)); col.setCellEditor(table.getDefaultEditor(Boolean.class)); JFrame f = new JFrame(); f.setSize(300, 300); f.add(new JScrollPane(table)); f.setVisible(true); }