Example usage for java.text SimpleDateFormat SimpleDateFormat

List of usage examples for java.text SimpleDateFormat SimpleDateFormat

Introduction

In this page you can find the example usage for java.text SimpleDateFormat SimpleDateFormat.

Prototype

public SimpleDateFormat(String pattern, DateFormatSymbols formatSymbols) 

Source Link

Document

Constructs a SimpleDateFormat using the given pattern and date format symbols.

Usage

From source file:Main.java

public static void main(String[] args) {
    String timeStamp = new SimpleDateFormat("EEE MMM dd hh:mm:ss yyyy", Locale.FRANCE).format(new Date());
    System.out.println(timeStamp);

}

From source file:Main.java

public static void main(String[] args) throws Exception {

    SimpleDateFormat sdf = new SimpleDateFormat("dd-MMMM-yyyy", Locale.ENGLISH);
    System.out.println(sdf.parse("29-July-2012"));

}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    Format formatter = new SimpleDateFormat("HH:mm:ss Z", Locale.CANADA);
    Date date = (Date) formatter.parseObject("21:44:07 Heure normale du Pacifique");
}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    Format formatter = new SimpleDateFormat("E, dd MMM yyyy", Locale.CANADA);
    Date date = (Date) formatter.parseObject("mar., 29 janv. 2002");
}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    Locale locale = Locale.FRENCH;

    DateFormat formatter = new SimpleDateFormat("HH:mm:ss zzzz", locale);
    String s = formatter.format(new Date());
    System.out.println(s);// ww w  .  j  a  v a  2s .  c om

}

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:Main.java

public static void main(String[] args) throws Exception {
    String input = "Thu Jun 06 2015 00:00:00 GMT+0530 (India Standard Time)";
    DateFormat inputFormat = new SimpleDateFormat("E MMM dd yyyy HH:mm:ss 'GMT'z", Locale.ENGLISH);
    Date date = inputFormat.parse(input);

    DateFormat outputFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss", Locale.ENGLISH);
    outputFormat.setTimeZone(TimeZone.getTimeZone("UTC"));

    String output = outputFormat.format(date);
    System.out.println(output);//ww w  .  j  a v a2 s  .  c o  m
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    String inputText = "Nov 10,2015";

    TimeZone utc = TimeZone.getTimeZone("UTC");

    SimpleDateFormat inputFormat = new SimpleDateFormat("MMM d,yyyy", Locale.US);
    inputFormat.setTimeZone(utc);//www . j av a 2  s.c o  m

    SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.US);
    outputFormat.setTimeZone(utc);

    Date parsed = inputFormat.parse(inputText);
    String outputText = outputFormat.format(parsed);

    System.out.println(outputText);
}

From source file:JFormattedTextFieldDateInputSampleELocaleFRENCH.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Date/Time Input");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JLabel label;/*www. ja v a  2  s . co m*/
    JFormattedTextField input;
    JPanel panel;

    BoxLayout layout = new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS);
    frame.setLayout(layout);

    Format dayOfWeek = new SimpleDateFormat("E", Locale.FRENCH);
    label = new JLabel("French day of week:");
    input = new JFormattedTextField(dayOfWeek);
    input.setValue(new Date());
    input.setColumns(20);

    panel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    panel.add(label);
    panel.add(input);

    frame.add(panel);
    frame.add(new JTextField());
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    DateFormatSymbols symbols = new DateFormatSymbols(new Locale("en", "US"));
    String[] defaultDays = symbols.getShortWeekdays();

    for (int i = 0; i < defaultDays.length; i++) {
        System.out.print(defaultDays[i] + "  ");
    }// w  w w  .j  a v a  2 s  .  c om
    System.out.println();

    String[] capitalDays = { "", "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" };
    symbols.setShortWeekdays(capitalDays);

    String[] modifiedDays = symbols.getShortWeekdays();
    for (int i = 0; i < modifiedDays.length; i++) {
        System.out.println(modifiedDays[i] + "  ");
    }

    SimpleDateFormat formatter = new SimpleDateFormat("E", symbols);
    Date today = new Date();
    String result = formatter.format(today);
    System.out.println(result);

}