Example usage for java.util Date Date

List of usage examples for java.util Date Date

Introduction

In this page you can find the example usage for java.util Date Date.

Prototype

public Date() 

Source Link

Document

Allocates a Date object and initializes it so that it represents the time at which it was allocated, measured to the nearest millisecond.

Usage

From source file:TimeTrial.java

public static void main(String[] args) {
    // Format Date into dd-MM-yyyy
    System.out.println("1) dd-MM-yyyy >>>" + DateFormatUtils.format(new Date(), "dd-MM-yyyy"));

    // Format Date into SMTP_DATETIME_FORMAT
    System.out.println("2) SMTP_DATETIME_FORMAT >>>" + DateFormatUtils.SMTP_DATETIME_FORMAT.format(new Date()));

    // Format Date into ISO_DATE_FORMAT
    System.out.println("3) ISO_DATE_FORMAT >>>" + DateFormatUtils.ISO_DATE_FORMAT.format(new Date()));

    // Format milliseconds in long
    System.out.println(//from   ww  w .ja  v a  2  s. c o  m
            "4) MMM dd yy HH:mm >>>" + DateFormatUtils.format(System.currentTimeMillis(), "MMM dd yy HH:mm"));

    // Format milliseconds in long using UTC timezone
    System.out.println(
            "5) MM/dd/yy HH:mm >>>" + DateFormatUtils.formatUTC(System.currentTimeMillis(), "MM/dd/yy HH:mm"));
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    SimpleDateFormat sdf = new SimpleDateFormat();
    DateFormatSymbols dfs = sdf.getDateFormatSymbols();

    String era[] = { "BCE", "CE" };
    dfs.setEras(era);//from   w ww  .  ja v  a2  s. c  om
    sdf.setDateFormatSymbols(dfs);

    sdf.applyPattern("MMMM d yyyy G");
    System.out.println(sdf.format(new Date()));
}

From source file:MainClass.java

public static void main(String[] args) {
    Date today = new Date();
    Locale[] locales = { US, UK, GERMANY, FRANCE };
    int[] styles = { FULL, LONG, MEDIUM, SHORT };
    String[] styleNames = { "FULL", "LONG", "MEDIUM", "SHORT" };
    DateFormat fmt = null;/* w ww  .  jav a 2 s.co m*/
    for (Locale locale : locales) {
        System.out.println("\nThe Date for " + locale.getDisplayCountry() + ":");
        for (int i = 0; i < styles.length; i++) {
            fmt = DateFormat.getDateInstance(styles[i], locale);
            System.out.println("\tIn " + styleNames[i] + " is " + fmt.format(today));
        }
    }
}

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//from  w ww .  ja  v  a2  s.  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//  ww  w  .  jav a 2  s.  c o m
    try {
        Date date = shortDf.parse("12/12/2006");
    } catch (ParseException e) {
    }
}

From source file:FormattedTest.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Formatted");
    Container contentPane = frame.getContentPane();
    JFormattedTextField ftf1 = new JFormattedTextField(new Integer(0));
    contentPane.add(ftf1, BorderLayout.NORTH);
    JFormattedTextField ftf2 = new JFormattedTextField(new Date());
    contentPane.add(ftf2, BorderLayout.SOUTH);
    frame.setSize(200, 100);//from  w ww  .  j av a  2s.co  m
    frame.show();
}

From source file:MainClass.java

public static void main(String[] args) {
    String pattern = "MM/dd/yyyy";
    SimpleDateFormat format = new SimpleDateFormat(pattern);
    try {// w w  w .  jav  a2  s .  co  m
        Date date = format.parse("12/31/2006");
        System.out.println(date);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    // formatting
    System.out.println(format.format(new Date()));
}

From source file:AntarcticaLocaleDemo.java

public static void main(String [] args) {
    Date now = new Date();

    DateFormat defaultFormat = DateFormat.getDateTimeInstance();
    String defaultString = defaultFormat.format (now);
    System.out.println ("Default : " + defaultString);

    DateFormat antarcticaFormat =
            DateFormat.getDateTimeInstance (
            DateFormat.FULL, DateFormat.FULL,
            new Locale ("en", "AQ"));
    String antarcticaString = antarcticaFormat.format (now);
    System.out.println ("Antarctica: " + antarcticaString);
}

From source file:DateFormatApp.java

public static void main(String args[]) {
    String pattern = "'The year is '";
    pattern += "yyyy GG";
    pattern += "'.\nThe month is '";
    pattern += "MMMMMMMMM";
    pattern += "'.\nIt is '";
    pattern += "hh";
    pattern += "' o''clock '";
    pattern += "a, zzzz";
    pattern += "'.'";
    SimpleDateFormat format = new SimpleDateFormat(pattern);
    String formattedDate = format.format(new Date());
    System.out.println(formattedDate);
}

From source file:Main.java

public static void main(String args[]) throws IOException {
    DatagramSocket socket = new DatagramSocket(DAYTIME_PORT);
    while (true) {
        byte buffer[] = new byte[256];
        DatagramPacket packet = new DatagramPacket(buffer, buffer.length);
        socket.receive(packet);//w ww.j  av a  2s. co m
        String date = new Date().toString();
        buffer = date.getBytes();
        // Get response address/port for client from packet
        InetAddress address = packet.getAddress();
        int port = packet.getPort();
        packet = new DatagramPacket(buffer, buffer.length, address, port);
        socket.send(packet);
    }
}