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

public static void main(String[] argv) throws Exception {
    DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG,
            Locale.getDefault());

    String s = dateFormat.format(new Date());
    System.out.println(s);/*from  w w w.j  a v a2s  .c om*/

}

From source file:Main.java

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

    SimpleDateFormat formatter = new SimpleDateFormat();

    StringBuffer sb = new StringBuffer();
    formatter.format(new Date(), sb, new FieldPosition(DateFormat.DATE_FIELD));
    System.out.println(sb);/*  w  w w .  j a  v a2 s.co  m*/
}

From source file:MessageFormatReuse.java

public static void main(String args[]) {
    String pattern = "{0}K was deleted on {1}.";
    MessageFormat formatter = new MessageFormat(pattern);

    Double kb = new Double(3.5);
    Date today = new Date();
    Object[] arguments = { kb, today };

    formatter.setLocale(Locale.US);
    System.out.println(formatter.format(arguments));
}

From source file:FormatDateLocale.java

public static void main(String[] args) {
    Locale[] locales = new Locale[] { Locale.JAPAN, Locale.CHINA, Locale.KOREA, Locale.TAIWAN, Locale.ITALY,
            Locale.FRANCE, Locale.GERMAN };

    Date today = new Date();

    for (Locale locale : locales) {
        System.out.println("Date format in " + locale.getDisplayName() + " = "
                + SimpleDateFormat.getDateInstance(SimpleDateFormat.LONG, locale).format(today).toUpperCase());
    }//w w w. j a  va2  s. c  o m
}

From source file:Main.java

public static void main(String[] args) {
    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();// w  w w. j  av a2s. co  m
    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[] 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);//from   w w  w.  j a  v a 2 s.co m

}

From source file:MainClass.java

public static void main(String[] argv) {
    String pattern = "{0}K was deleted on {1}.";
    MessageFormat formatter = new MessageFormat(pattern);

    Double kb = new Double(3.5);
    Date today = new Date();
    Object[] arguments = { kb, today };

    formatter.setLocale(Locale.US);
    System.out.println(formatter.format(arguments));

    formatter.setLocale(Locale.FRANCE);
    System.out.println(formatter.format(arguments));

    pattern = "On {1}, {0}K was deleted.";
    formatter.applyPattern(pattern);/*from   ww w  .j  av a2 s  .  co m*/
    System.out.println(formatter.format(arguments));

    formatter.setLocale(Locale.US);
    System.out.println(formatter.format(arguments));
}

From source file:Main.java

public static void main(String[] args) {
    int[] anArray = new int[1000];
    Random generator = new Random();
    for (int i = 0; i < 1000; i++) {
        anArray[i] = (generator.nextInt(1000) + 1);
    }//  w ww  . j  a  v a  2  s. c  om
    Date before = new Date();
    Arrays.sort(anArray);
    Date after = new Date();
    System.out.println("milli seconds" + (after.getTime() - before.getTime()));
}

From source file:Main.java

public static void main(String[] args) {
    List<Person> list = new ArrayList<Person>();
    for (int i = 10; i > 0; i--) {
        list.add(new Person(i, "name" + String.valueOf(i), new Date()));
    }/* w  w  w. ja va 2  s .c  om*/
    System.out.println(list);
    Collections.sort(list);
    System.out.println(list);
}

From source file:Main.java

public static void main(final String[] args) throws ParseException {
    final SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
    f.setTimeZone(TimeZone.getTimeZone("UTC"));
    System.out.println(f.format(new Date()));
}