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

public static void main(String[] args) {
    // creating timer task, timer
    TimerTask tasknew = new MyTimerTask();
    Timer timer = new Timer();

    // scheduling the task
    timer.schedule(tasknew, new Date());
}

From source file:MainClass.java

public static void main(String[] a) {
    Calendar calendar = new GregorianCalendar();
    calendar.setTime(new Date());

    System.out.println("ERA: " + calendar.get(Calendar.ERA));
    System.out.println("YEAR: " + calendar.get(Calendar.YEAR));
    System.out.println("MONTH: " + calendar.get(Calendar.MONTH));
    System.out.println("WEEK_OF_YEAR: " + calendar.get(Calendar.WEEK_OF_YEAR));
    System.out.println("WEEK_OF_MONTH: " + calendar.get(Calendar.WEEK_OF_MONTH));
    System.out.println("DATE: " + calendar.get(Calendar.DATE));
    System.out.println("DAY_OF_MONTH: " + calendar.get(Calendar.DAY_OF_MONTH));
    System.out.println("DAY_OF_WEEK: " + calendar.get(Calendar.DAY_OF_WEEK));
    System.out.println("DAY_OF_WEEK_IN_MONTH: " + calendar.get(Calendar.DAY_OF_WEEK_IN_MONTH));
    System.out.println("AM_PM: " + calendar.get(Calendar.AM_PM));
    System.out.println("MILLISECOND: " + calendar.get(Calendar.MILLISECOND));
    System.out.println("ZONE_OFFSET: " + (calendar.get(Calendar.ZONE_OFFSET) / (60 * 60 * 1000)));
    System.out.println("DST_OFFSET: " + (calendar.get(Calendar.DST_OFFSET) / (60 * 60 * 1000)));
}

From source file:MyTimerTask.java

public static void main(String[] args) {
    // creating timer task, timer
    TimerTask task = new MyTimerTask();
    Timer timer = new Timer();

    // scheduling the task
    timer.scheduleAtFixedRate(task, new Date(), 1000);

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    String s = new Date().toString();
    JTextPane jtp = new JTextPane();
    StyledDocument doc = (StyledDocument) jtp.getDocument();

    SimpleAttributeSet normal = new SimpleAttributeSet();
    StyleConstants.setFontFamily(normal, "SansSerif");
    StyleConstants.setFontSize(normal, 16);

    SimpleAttributeSet boldBlue = new SimpleAttributeSet(normal);
    StyleConstants.setBold(boldBlue, true);
    StyleConstants.setForeground(boldBlue, Color.blue);

    SimpleAttributeSet highAlert = new SimpleAttributeSet(boldBlue);
    StyleConstants.setFontSize(highAlert, 18);
    StyleConstants.setItalic(highAlert, true);
    StyleConstants.setForeground(highAlert, Color.red);

    doc.insertString(doc.getLength(), s + "\n", normal);
    doc.insertString(doc.getLength(), s + "\n", boldBlue);
    doc.insertString(doc.getLength(), s + "\n", highAlert);
    f.add(jtp);/* w  w w  . j a va2  s .  c  om*/
    f.pack();
    f.setLocationRelativeTo(null);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Bean demo = new Bean();
    Class clazz = demo.getClass();

    Field field = clazz.getField("id");
    field.set(demo, new Long(10));
    Object value = field.get(demo);
    System.out.println("Value = " + value);

    field = clazz.getField("now");
    field.set(null, new Date());
    value = field.get(null);/*from w w w  .j av a2s .c  o m*/
    System.out.println("Value = " + value);
}

From source file:MyTimerTask.java

public static void main(String[] args) {
    // creating timer task, timer
    TimerTask task = new MyTimerTask();
    Timer timer = new Timer();

    // scheduling the task
    timer.scheduleAtFixedRate(task, new Date(), 1000);

    // checking scheduled execution time
    System.out.println("Time is :" + task.scheduledExecutionTime());
}

From source file:MainClass.java

public static void main(String[] args) {
    StopWatch stWatch = new StopWatch();

    //Start StopWatch
    stWatch.start();/*from   www.  ja  v a 2 s .c o  m*/

    //Get iterator for all days in a week starting Monday
    Iterator itr = DateUtils.iterator(new Date(), DateUtils.RANGE_WEEK_MONDAY);

    while (itr.hasNext()) {
        Calendar gCal = (Calendar) itr.next();
        System.out.println(gCal.getTime());
    }

    //Stop StopWatch
    stWatch.stop();
    System.out.println("Time Taken >>" + stWatch.getTime());

}

From source file:ChangeEra.java

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

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

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

From source file:MyTimerTask.java

public static void main(String[] args) {
    // creating timer task, timer
    TimerTask tasknew = new MyTimerTask();
    Timer timer = new Timer();

    // scheduling the task at interval
    timer.schedule(tasknew, new Date(), 1000);
}

From source file:MyTimerTask.java

public static void main(String[] args) {
    // creating timer task, timer
    TimerTask tasknew = new MyTimerTask();
    Timer timer = new Timer();

    // scheduling the task
    timer.scheduleAtFixedRate(tasknew, new Date(), 10);

    // cancel task
    timer.cancel();/*w  ww .j a v  a 2  s  .c  o m*/

    // purging the timer
    System.out.println("purge value :" + timer.purge());
}