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[] args) {

    String strDateFormat = "EEEE";
    SimpleDateFormat sdf = new SimpleDateFormat(strDateFormat);
    System.out.println("Current day of week in EEEE format : " + sdf.format(new Date()));

}

From source file:Main.java

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

    SimpleDateFormat formatter = new SimpleDateFormat();
    formatter.applyLocalizedPattern("MMM");
    String s = formatter.format(new Date());
    System.out.println(s);//from  ww w . ja v  a  2 s.  c  o m
}

From source file:Main.java

public static void main(String[] args) {
    Set<Object> set = new HashSet<Object>();
    set.add("A");
    set.add(new Long(10));
    set.add(new Date());

    List<Object> list = new ArrayList<Object>(set);
    for (int i = 0; i < list.size(); i++) {
        Object o = list.get(i);//w w  w  .j  av a  2s. co  m
        System.out.println("Object = " + o);
    }
}

From source file:MainClass.java

public static void main(String args[]) {
    Date date = new Date();
    DateFormat df;//from   w w w.j  ava 2 s  . c  om

    df = DateFormat.getDateInstance(DateFormat.SHORT, Locale.JAPAN);
    System.out.println("Japan: " + df.format(date));

    df = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.KOREA);
    System.out.println("Korea: " + df.format(date));

    df = DateFormat.getDateInstance(DateFormat.LONG, Locale.UK);
    System.out.println("United Kingdom: " + df.format(date));

    df = DateFormat.getDateInstance(DateFormat.FULL, Locale.US);
    System.out.println("United States: " + df.format(date));
}

From source file:Main.java

public static void main(String[] argv) {
    JFormattedTextField f = new JFormattedTextField(new SimpleDateFormat("yyyy-M-d"));
    f.setValue(new Date());

    DateFormatter fmt = (DateFormatter) f.getFormatter();
    fmt.setFormat(new SimpleDateFormat("d/M/yyyy"));

    f.setValue(f.getValue());//from w  w w.ja v  a2s.  c  o  m
}

From source file:Main.java

public static void main(String[] args) {
    Set<Object> set = new HashSet<Object>();
    set.add("A");
    set.add(new Long(10));
    set.add(new Date());

    List<Object> list = new ArrayList<Object>(set);
    Object[] objects = list.toArray();

    for (int i = 0; i < objects.length; i++) {
        Object object = objects[i];
        System.out.println("Object = " + object);
    }//from w w  w .  ja  v  a2  s  .c o m
}

From source file:Main.java

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

    Format formatter = new SimpleDateFormat("MMM");
    CharacterIterator s = formatter.formatToCharacterIterator(new Date());
    System.out.println(s.last());
}

From source file:MessageFormatApp.java

public static void main(String args[]) {
    String pattern = "The time is {0,time} and ";
    pattern += "your lucky number is {1,number}.";
    MessageFormat format = new MessageFormat(pattern);
    Object objects[] = { new Date(), new Integer((int) (Math.random() * 1000)) };
    String formattedOutput = format.format(objects);
    System.out.println(formattedOutput);
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    Date today = new Date();
    long millisecondsPerDay = 24 * 60 * 60 * 1000;

    URL u = new URL("http://www.java2s.com");
    URLConnection uc = u.openConnection();
    uc.setIfModifiedSince((new Date(today.getTime() - millisecondsPerDay)).getTime());
    InputStream in = new BufferedInputStream(uc.getInputStream());
    Reader r = new InputStreamReader(in);
    int c;/*w w w.j  a va  2s .c o m*/
    while ((c = r.read()) != -1) {
        System.out.print((char) c);
    }
}

From source file:MainClass.java

public static void main(String[] a) throws Exception {
    Date d1 = new GregorianCalendar(2000, 11, 31, 23, 59).getTime();

    Date today = new Date();

    long diff = today.getTime() - d1.getTime();

    System.out.println(//from   www  .j av  a  2 s  . c om
            "The 21st century (up to " + today + ") is " + (diff / (1000 * 60 * 60 * 24)) + " days old.");
}