List of usage examples for java.text DateFormat getDateInstance
public static final DateFormat getDateInstance(int style)
From source file:Main.java
public static void main(String args[]) { SimpleDateFormat df = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.SHORT); System.out.println("The short date format is " + df.toPattern()); Locale loc = Locale.ITALY; df = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.SHORT, loc); System.out.println("The short date format is " + df.toPattern()); }
From source file:MainClass.java
public static void main(String[] args) { DateFormat shortDf = DateFormat.getDateInstance(DateFormat.SHORT); DateFormat mediumDf = DateFormat.getDateInstance(DateFormat.MEDIUM); DateFormat longDf = DateFormat.getDateInstance(DateFormat.LONG); DateFormat fullDf = DateFormat.getDateInstance(DateFormat.FULL); System.out.println(shortDf.format(new Date())); System.out.println(mediumDf.format(new Date())); System.out.println(longDf.format(new Date())); System.out.println(fullDf.format(new Date())); // parsing/* w w w . j av a 2s. c o m*/ try { Date date = shortDf.parse("Jan 32, 2005"); } catch (ParseException e) { } }
From source file:MainClass.java
public static void main(String[] args) { DateFormat shortDf = DateFormat.getDateInstance(DateFormat.SHORT); DateFormat mediumDf = DateFormat.getDateInstance(DateFormat.MEDIUM); DateFormat longDf = DateFormat.getDateInstance(DateFormat.LONG); DateFormat fullDf = DateFormat.getDateInstance(DateFormat.FULL); System.out.println(shortDf.format(new Date())); System.out.println(mediumDf.format(new Date())); System.out.println(longDf.format(new Date())); System.out.println(fullDf.format(new Date())); // parsing/* w w w .j a v a2 s.co m*/ try { Date date = shortDf.parse("12/12/2006"); } catch (ParseException e) { } }
From source file:DateTest.java
public static void main(String[] args) throws ParseException { DateFormat formatter = DateFormat.getDateInstance(DateFormat.SHORT); formatter.setLenient(false);/*from www . j av a 2s .com*/ Date theDate = formatter.parse(args[0]); System.out.println(theDate); }
From source file:Main.java
public static void main(String[] argv) { JFormattedTextField tft2 = new JFormattedTextField(DateFormat.getDateInstance(DateFormat.SHORT)); tft2.setValue(new Date()); }
From source file:JFormattedTextFieldDateInputSampleDateFormatSHORT.java
public static void main(String args[]) { JFrame frame = new JFrame("Date/Time Input"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel label;/*from w w w . ja v a 2 s . c o m*/ JFormattedTextField input; JPanel panel; BoxLayout layout = new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS); frame.setLayout(layout); Format shortDate = DateFormat.getDateInstance(DateFormat.SHORT); label = new JLabel("Short date:"); input = new JFormattedTextField(shortDate); input.setValue(new Date()); input.setColumns(20); panel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); panel.add(label); panel.add(input); frame.add(panel); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static boolean isValidDateStr(String date) throws Exception { DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT); df.setLenient(false);/* w ww . j av a2 s. co m*/ df.parse(date); return true; }
From source file:Main.java
public static String mediumFormat(Date date) { DateFormat dateFormat1 = DateFormat.getDateInstance(DateFormat.MEDIUM); return dateFormat1.format(date); }
From source file:Main.java
public static String dateFormatShort(Date date) { DateFormat dateFormat1 = DateFormat.getDateInstance(DateFormat.SHORT); return dateFormat1.format(date); }
From source file:Main.java
public static String getFormatDateStr(final Date date) { if (null == date) { return null; }/* w w w.j a v a 2s . co m*/ return DateFormat.getDateInstance(DateFormat.DEFAULT).format(date); }