Swing: Date Time Editor : Calendar Date « Development Class « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Class
8. Collections Data Structure
9. Data Type
10. Database SQL JDBC
11. Design Pattern
12. Development Class
13. EJB3
14. Email
15. Event
16. File Input Output
17. Game
18. Generics
19. GWT
20. Hibernate
21. I18N
22. J2EE
23. J2ME
24. JDK 6
25. JNDI LDAP
26. JPA
27. JSP
28. JSTL
29. Language Basics
30. Network Protocol
31. PDF RTF
32. Reflection
33. Regular Expressions
34. Scripting
35. Security
36. Servlets
37. Spring
38. Swing Components
39. Swing JFC
40. SWT JFace Eclipse
41. Threads
42. Tiny Application
43. Velocity
44. Web Services SOA
45. XML
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java » Development Class » Calendar DateScreenshots 
Swing: Date Time Editor
Swing: Date Time Editor
     
/*
Swing, Second Edition
by Matthew Robinson, Pavel Vorobiev

*/

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.text.DateFormat;
import java.text.FieldPosition;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.Iterator;
import java.util.NoSuchElementException;

import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.KeyStroke;
import javax.swing.SwingConstants;
import javax.swing.border.EmptyBorder;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.plaf.basic.BasicArrowButton;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.Caret;
import javax.swing.text.DefaultEditorKit;
import javax.swing.text.JTextComponent;
import javax.swing.text.Keymap;
import javax.swing.text.PlainDocument;
import javax.swing.text.TextAction;

public class DateTimeEditor extends JPanel {
  public static final long ONE_SECOND = 1000;

  public static final long ONE_MINUTE = 60 * ONE_SECOND;

  public static final long ONE_HOUR = 60 * ONE_MINUTE;

  public static final long ONE_DAY = 24 * ONE_HOUR;

  public static final long ONE_WEEK = * ONE_DAY;

  public final static int TIME = 0;

  public final static int DATE = 1;

  public final static int DATETIME = 2;

  private int m_timeOrDateType;

  private int m_lengthStyle;

  private DateFormat m_format;

  private Calendar m_calendar = Calendar.getInstance();

  private ArrayList m_fieldPositions = new ArrayList();

  private Date m_lastDate = new Date();

  private Caret m_caret;

  private int m_curField = -1;

  private JTextField m_textField;

  private Spinner m_spinner;

  private AbstractAction m_upAction = new UpDownAction(1"up");

  private AbstractAction m_downAction = new UpDownAction(-1"down");

  private boolean m_settingDateText = false// BUG FIX

  private int[] m_fieldTypes = DateFormat.ERA_FIELD, DateFormat.YEAR_FIELD,
      DateFormat.MONTH_FIELD, DateFormat.DATE_FIELD,
      DateFormat.HOUR_OF_DAY1_FIELD, DateFormat.HOUR_OF_DAY0_FIELD,
      DateFormat.MINUTE_FIELD, DateFormat.SECOND_FIELD,
      DateFormat.MILLISECOND_FIELD, DateFormat.DAY_OF_WEEK_FIELD,
      DateFormat.DAY_OF_YEAR_FIELD,
      DateFormat.DAY_OF_WEEK_IN_MONTH_FIELD,
      DateFormat.WEEK_OF_YEAR_FIELD, DateFormat.WEEK_OF_MONTH_FIELD,
      DateFormat.AM_PM_FIELD, DateFormat.HOUR1_FIELD,
      DateFormat.HOUR0_FIELD };

  public DateTimeEditor() {
    m_timeOrDateType = DATETIME;
    m_lengthStyle = DateFormat.SHORT;
    init();
  }

  public DateTimeEditor(int timeOrDateType) {
    m_timeOrDateType = timeOrDateType;
    m_lengthStyle = DateFormat.FULL;
    init();
  }

  public DateTimeEditor(int timeOrDateType, int lengthStyle) {
    m_timeOrDateType = timeOrDateType;
    m_lengthStyle = lengthStyle;
    init();
  }

  private void init() {
    setLayout(new BorderLayout());
    m_textField = new JTextField();

    m_textField.setDocument(new DateTimeDocument())// BUG FIX

    m_spinner = new Spinner();
    m_spinner.getIncrementButton().addActionListener(m_upAction);
    m_spinner.getDecrementButton().addActionListener(m_downAction);
    add(m_textField, "Center");
    add(m_spinner, "East");
    m_caret = m_textField.getCaret();
    m_caret.addChangeListener(new ChangeListener() {
      public void stateChanged(ChangeEvent evt) {
        setCurField();
      }
    });
    setupKeymap();
    reinit();
  }

  protected class DateTimeDocument extends PlainDocument {
    public void insertString(int offset, String str, AttributeSet a)
        throws BadLocationException {
      if (m_settingDateText)
        super.insertString(offset, str, a);
    }
  // BUG FIX

  public int getTimeOrDateType() {
    return m_timeOrDateType;
  }

  public void setTimeOrDateType(int timeOrDateType) {
    m_timeOrDateType = timeOrDateType;
    reinit();
  }

  public int getLengthStyle() {
    return m_lengthStyle;
  }

  public void setLengthStyle(int lengthStyle) {
    m_lengthStyle = lengthStyle;
    reinit();
  }

  public Date getDate() {
    return (m_lastDate);
  }

  // public void setDate(Date date)
  // {
  //    m_lastDate = date;
  //    m_calendar.setTime(m_lastDate);
  //    m_textField.setText(m_format.format(m_lastDate));
  //    getFieldPositions();
  // }

  public void setDate(Date date) {
    m_lastDate = date;
    m_calendar.setTime(m_lastDate);
    m_settingDateText = true;
    m_textField.setText(m_format.format(m_lastDate));
    m_settingDateText = false;
    getFieldPositions();
  // BUG FIX

  private int getFieldBeginIndex(int fieldNum) {
    int beginIndex = -1;
    for (Iterator iter = m_fieldPositions.iterator(); iter.hasNext();) {
      FieldPosition fieldPos = (FieldPositioniter.next();
      if (fieldPos.getField() == fieldNum) {
        beginIndex = fieldPos.getBeginIndex();
        break;
      }
    }
    return (beginIndex);
  }

  private FieldPosition getFieldPosition(int fieldNum) {
    FieldPosition result = null;
    for (Iterator iter = m_fieldPositions.iterator(); iter.hasNext();) {
      FieldPosition fieldPosition = (FieldPositioniter.next();
      if (fieldPosition.getField() == fieldNum) {
        result = fieldPosition;
        break;
      }
    }
    return (result);
  }

  private void reinit() {
    setupFormat();
    setDate(m_lastDate);
    m_caret.setDot(0);
    setCurField();
    repaint();
  }

  protected void setupFormat() {
    switch (m_timeOrDateType) {
    case TIME:
      m_format = DateFormat.getTimeInstance(m_lengthStyle);
      break;
    case DATE:
      m_format = DateFormat.getDateInstance(m_lengthStyle);
      break;
    case DATETIME:
      m_format = DateFormat.getDateTimeInstance(m_lengthStyle,
          m_lengthStyle);
      break;
    }
  }

  protected class UpDownAction extends AbstractAction {
    int m_direction; // +1 = up; -1 = down

    public UpDownAction(int direction, String name) {
      super(name);
      m_direction = direction;
    }

    public void actionPerformed(ActionEvent evt) {
      if (!this.isEnabled())
        return;
      boolean dateSet = true;
      switch (m_curField) {
      case DateFormat.AM_PM_FIELD:
        m_lastDate.setTime(m_lastDate.getTime()
            (m_direction * 12 * ONE_HOUR));
        break;
      case DateFormat.DATE_FIELD:
      case DateFormat.DAY_OF_WEEK_FIELD:
      case DateFormat.DAY_OF_WEEK_IN_MONTH_FIELD:
      case DateFormat.DAY_OF_YEAR_FIELD:
        m_lastDate.setTime(m_lastDate.getTime()
            (m_direction * ONE_DAY));
        break;
      case DateFormat.ERA_FIELD:
        dateSet = false;
        break;
      case DateFormat.HOUR0_FIELD:
      case DateFormat.HOUR1_FIELD:
      case DateFormat.HOUR_OF_DAY0_FIELD:
      case DateFormat.HOUR_OF_DAY1_FIELD:
        m_lastDate.setTime(m_lastDate.getTime()
            (m_direction * ONE_HOUR));
        break;
      case DateFormat.MILLISECOND_FIELD:
        m_lastDate.setTime(m_lastDate.getTime() (m_direction * 1));
        break;
      case DateFormat.MINUTE_FIELD:
        m_lastDate.setTime(m_lastDate.getTime()
            (m_direction * ONE_MINUTE));
        break;
      case DateFormat.MONTH_FIELD:
        m_calendar.set(Calendar.MONTH, m_calendar.get(Calendar.MONTH)
            + m_direction);
        m_lastDate = m_calendar.getTime();
        break;
      case DateFormat.SECOND_FIELD:
        m_lastDate.setTime(m_lastDate.getTime()
            (m_direction * ONE_SECOND));
        break;
      case DateFormat.WEEK_OF_MONTH_FIELD:
        m_calendar.set(Calendar.WEEK_OF_MONTH, m_calendar
            .get(Calendar.WEEK_OF_MONTH)
            + m_direction);
        m_lastDate = m_calendar.getTime();
        break;
      case DateFormat.WEEK_OF_YEAR_FIELD:
        m_calendar.set(Calendar.WEEK_OF_MONTH, m_calendar
            .get(Calendar.WEEK_OF_MONTH)
            + m_direction);
        m_lastDate = m_calendar.getTime();
        break;
      case DateFormat.YEAR_FIELD:
        m_calendar.set(Calendar.YEAR, m_calendar.get(Calendar.YEAR)
            + m_direction);
        m_lastDate = m_calendar.getTime();
        break;
      default:
        dateSet = false;
      }

      if (dateSet) {
        int fieldId = m_curField;
        setDate(m_lastDate);
        FieldPosition fieldPosition = getFieldPosition(fieldId);
        m_caret.setDot(fieldPosition.getBeginIndex());

        m_textField.requestFocus();
        repaint();
      }
    }
  }

  protected class BackwardAction extends TextAction {
    BackwardAction(String name) {
      super(name);
    }

    public void actionPerformed(ActionEvent e) {
      JTextComponent target = getTextComponent(e);
      if (target != null) {
        int dot = target.getCaretPosition();
        if (dot > 0) {
          FieldPosition position = getPrevField(dot);
          if (position != null)
            target.setCaretPosition(position.getBeginIndex());
          else {
            position = getFirstField();
            if (position != null)
              target.setCaretPosition(position.getBeginIndex());
          }
        else
          target.getToolkit().beep();
        target.getCaret().setMagicCaretPosition(null);
      }
    }
  }

  protected class ForwardAction extends TextAction {
    ForwardAction(String name) {
      super(name);
    }

    public void actionPerformed(ActionEvent e) {
      JTextComponent target = getTextComponent(e);
      if (target != null) {
        FieldPosition position = getNextField(target.getCaretPosition());
        if (position != null)
          target.setCaretPosition(position.getBeginIndex());
        else {
          position = getLastField();
          if (position != null)
            target.setCaretPosition(position.getBeginIndex());
        }
        target.getCaret().setMagicCaretPosition(null);
      }
    }
  }

  protected class BeginAction extends TextAction {
    BeginAction(String name) {
      super(name);
    }

    public void actionPerformed(ActionEvent e) {
      JTextComponent target = getTextComponent(e);
      if (target != null) {
        FieldPosition position = getFirstField();
        if (position != null)
          target.setCaretPosition(position.getBeginIndex());
      }
    }
  }

  protected class EndAction extends TextAction {
    EndAction(String name) {
      super(name);
    }

    public void actionPerformed(ActionEvent e) {
      JTextComponent target = getTextComponent(e);
      if (target != null) {
        FieldPosition position = getLastField();
        if (position != null)
          target.setCaretPosition(position.getBeginIndex());
      }
    }
  }

  protected void setupKeymap() {
    Keymap keymap = m_textField.addKeymap("DateTimeKeymap"null);
    keymap.addActionForKeyStroke(KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0),
        m_upAction);
    keymap.addActionForKeyStroke(KeyStroke
        .getKeyStroke(KeyEvent.VK_DOWN, 0), m_downAction);
    keymap.addActionForKeyStroke(KeyStroke
        .getKeyStroke(KeyEvent.VK_LEFT, 0)new BackwardAction(
        DefaultEditorKit.backwardAction));
    keymap.addActionForKeyStroke(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT,
        0)new ForwardAction(DefaultEditorKit.forwardAction));
    keymap.addActionForKeyStroke(KeyStroke
        .getKeyStroke(KeyEvent.VK_HOME, 0)new BeginAction(
        DefaultEditorKit.beginAction));
    keymap.addActionForKeyStroke(
        KeyStroke.getKeyStroke(KeyEvent.VK_END, 0)new EndAction(
            DefaultEditorKit.endAction));
    m_textField.setKeymap(keymap);
  }

  private void getFieldPositions() {
    m_fieldPositions.clear();
    for (int ctr = 0; ctr < m_fieldTypes.length; ++ctr) {
      int fieldId = m_fieldTypes[ctr];
      FieldPosition fieldPosition = new FieldPosition(fieldId);
      StringBuffer formattedField = new StringBuffer();
      m_format.format(m_lastDate, formattedField, fieldPosition);
      if (fieldPosition.getEndIndex() 0)
        m_fieldPositions.add(fieldPosition);
    }
    m_fieldPositions.trimToSize();
    Collections.sort(m_fieldPositions, new Comparator() {
      public int compare(Object o1, Object o2) {
        return (((FieldPositiono1).getBeginIndex() ((FieldPositiono2)
            .getBeginIndex());
      }
    });
  }

  private FieldPosition getField(int caretLoc) {
    FieldPosition fieldPosition = null;
    for (Iterator iter = m_fieldPositions.iterator(); iter.hasNext();) {
      FieldPosition chkFieldPosition = (FieldPositioniter.next();
      if ((chkFieldPosition.getBeginIndex() <= caretLoc)
          && (chkFieldPosition.getEndIndex() > caretLoc)) {
        fieldPosition = chkFieldPosition;
        break;
      }
    }
    return (fieldPosition);
  }

  private FieldPosition getPrevField(int caretLoc) {
    FieldPosition fieldPosition = null;
    for (int ctr = m_fieldPositions.size() 1; ctr > -1; --ctr) {
      FieldPosition chkFieldPosition = (FieldPositionm_fieldPositions
          .get(ctr);
      if (chkFieldPosition.getEndIndex() <= caretLoc) {
        fieldPosition = chkFieldPosition;
        break;
      }
    }
    return (fieldPosition);
  }

  private FieldPosition getNextField(int caretLoc) {
    FieldPosition fieldPosition = null;
    for (Iterator iter = m_fieldPositions.iterator(); iter.hasNext();) {
      FieldPosition chkFieldPosition = (FieldPositioniter.next();
      if (chkFieldPosition.getBeginIndex() > caretLoc) {
        fieldPosition = chkFieldPosition;
        break;
      }
    }
    return (fieldPosition);
  }

  private FieldPosition getFirstField() {
    FieldPosition result = null;
    try {
      result = ((FieldPositionm_fieldPositions.get(0));
    catch (NoSuchElementException ex) {
    }
    return (result);
  }

  private FieldPosition getLastField() {
    FieldPosition result = null;
    try {
      result = ((FieldPositionm_fieldPositions.get(m_fieldPositions
          .size() 1));
    catch (NoSuchElementException ex) {
    }
    return (result);
  }

  private void setCurField() {
    FieldPosition fieldPosition = getField(m_caret.getDot());
    if (fieldPosition != null) {
      if (m_caret.getDot() != fieldPosition.getBeginIndex())
        m_caret.setDot(fieldPosition.getBeginIndex());
    else {
      fieldPosition = getPrevField(m_caret.getDot());
      if (fieldPosition != null)
        m_caret.setDot(fieldPosition.getBeginIndex());
      else {
        fieldPosition = getFirstField();
        if (fieldPosition != null)
          m_caret.setDot(fieldPosition.getBeginIndex());
      }
    }

    if (fieldPosition != null)
      m_curField = fieldPosition.getField();
    else
      m_curField = -1;
  }

  public void setEnabled(boolean enable) {
    m_textField.setEnabled(enable);
    m_spinner.setEnabled(enable);
  }

  public boolean isEnabled() {
    return (m_textField.isEnabled() && m_spinner.isEnabled());
  }

  public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent evt) {
        System.exit(0);
      }
    });

    JPanel panel = new JPanel(new BorderLayout());
    panel.setBorder(new EmptyBorder(5555));
    frame.setContentPane(panel);
    final DateTimeEditor field = new DateTimeEditor(
        DateTimeEditor.DATETIME, DateFormat.FULL);
    panel.add(field, "North");

    JPanel buttonBox = new JPanel(new GridLayout(22));
    JButton showDateButton = new JButton("Show Date");
    buttonBox.add(showDateButton);

    final JComboBox timeDateChoice = new JComboBox();
    timeDateChoice.addItem("Time");
    timeDateChoice.addItem("Date");
    timeDateChoice.addItem("Date/Time");
    timeDateChoice.setSelectedIndex(2);
    timeDateChoice.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent evt) {
        field.setTimeOrDateType(timeDateChoice.getSelectedIndex());
      }
    });
    buttonBox.add(timeDateChoice);

    JButton toggleButton = new JButton("Toggle Enable");
    buttonBox.add(toggleButton);
    showDateButton.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent evt) {
        System.out.println(field.getDate());
      }
    });
    toggleButton.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent evt) {
        field.setEnabled(!field.isEnabled());
      }
    });
    panel.add(buttonBox, "South");

    final JComboBox lengthStyleChoice = new JComboBox();
    lengthStyleChoice.addItem("Full");
    lengthStyleChoice.addItem("Long");
    lengthStyleChoice.addItem("Medium");
    lengthStyleChoice.addItem("Short");
    lengthStyleChoice.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent evt) {
        field.setLengthStyle(lengthStyleChoice.getSelectedIndex());
      }
    });
    buttonBox.add(lengthStyleChoice);

    frame.pack();
    Dimension dim = frame.getToolkit().getScreenSize();
    frame.setLocation(dim.width / - frame.getWidth() 2, dim.height / 2
        - frame.getHeight() 2);
    frame.show();
  }
}

class Spinner extends JPanel
{
   private int m_orientation = SwingConstants.VERTICAL;
   private BasicArrowButton m_incrementButton;
   private BasicArrowButton m_decrementButton;

   public Spinner() { createComponents()}

   public Spinner(int orientation)
   {
      m_orientation = orientation;
      createComponents();
   }

   public void setEnabled(boolean enable)
   {
      m_incrementButton.setEnabled(enable);
      m_decrementButton.setEnabled(enable);
   }

   public boolean isEnabled()
   {
      return (m_incrementButton.isEnabled() &&
         m_decrementButton.isEnabled());
   }
   
   protected void createComponents()
   {
      if (m_orientation == SwingConstants.VERTICAL)
      {
         setLayout(new GridLayout(21));
         m_incrementButton = new BasicArrowButton(
            SwingConstants.NORTH);
         m_decrementButton = new BasicArrowButton(
            SwingConstants.SOUTH);
         add(m_incrementButton);
         add(m_decrementButton);
      }
      else if (m_orientation == SwingConstants.HORIZONTAL)
      {
         setLayout(new GridLayout(12));
         m_incrementButton = new BasicArrowButton(
            SwingConstants.EAST);
         m_decrementButton = new BasicArrowButton(
            SwingConstants.WEST);
         add(m_decrementButton);
         add(m_incrementButton);
      }
   }

   public JButton getIncrementButton() { 
      return (m_incrementButton)}
   public JButton getDecrementButton() { 
      return (m_decrementButton)}

   public static void main(String[] args)
   {
      JFrame frame = new JFrame();
      JPanel panel = (JPanelframe.getContentPane();
      panel.setLayout(new BorderLayout());
      JTextField  field = new JTextField(20);
      Spinner spinner = new Spinner();

      panel.add(field, "Center");
      panel.add(spinner, "East");

      Dimension dim = frame.getToolkit().getScreenSize();
      frame.setLocation(dim.width/- frame.getWidth()/2,
         dim.height/- frame.getHeight()/2);
      frame.pack();
      frame.show();
   }
}



           
         
    
    
    
    
  
Related examples in the same category
1. Create a Date object using the Calendar class
2. When does the UNIX date get into troubleWhen does the UNIX date get into trouble
3. Trivial class to show use of Date and Calendar objectsTrivial class to show use of Date and Calendar objects
4. Convert longs (time_t in UNIX terminology) to seconds
5. Show use of Calendar objectsShow use of Calendar objects
6. How quickly can you press return
7. Easter - compute the day on which Easter fallsEaster - compute the day on which Easter falls
8. Show use of Calendar get() method with various parameters
9. TimeComputation for processing sqrt and Input and Output operations.
10. Bean to display a month calendar in a JPanelBean to display a month calendar in a JPanel
11. Show some date uses 1
12. Show dates before 1970
13. Compare Dates
14. Compare File Dates
15. If a date is after another date
16. If a date is before another date
17. Compute days between 2 dates
18. Show some calendar calculations
19. The best way to format a date/time is to use
20. Create SimpleDateFormats from a string read from a file
21. DateCalAdd -- compute the difference between two dates
22. Show some date uses
23. Calendar DemoCalendar Demo
24. DateDiff -- compute the difference between two dates
25. DateAdd -- compute the difference between two dates
26. Increment and Decrement a Date Using the Calendar Class
27. Increment and Decrement Months Using the Calendar Class
28. Add or subtract days to current date using Java Calendar
29. Subtract days from current date using Calendar.add method
30. Add hours to current date using Calendar.add method
31. Subtract hours from current date using Calendar.add method
32. Add minutes to current date using Calendar.add method
33. Subtract minutes from current date using Calendar.add method
34. Add months to current date using Calendar.add method
35. Subtract months from current date using Calendar.add method
36. Add seconds to current date using Calendar.add method
37. Subtract seconds from current time using Calendar.add method
38. Add week to current date using Calendar.add method
39. Add hours, minutes or seconds to a date
40. Subtract week from current date
41. Add year to current date using Calendar.add method
42. Add 10 months to the calendar
43. Subtract 1 year from the calendar
44. Subtract year from current date
45. Calendar adjust date automatically
46. Display Day of Week using Java Calendar
47. Display Month of year using Java Calendar
48. Display full date time
49. Get a List of Month Names
50. Get current date, year and month
51. Get Week of month and year using Java Calendar
52. Get the number of days in that month
53. Get the current month name
54. Get day, month, year value from the current date
55. Convert day of the year to date
56. Pass the year information to the calendar object
57. Get the last date of a month
58. Convert day of year to day of month
59. Determine the day of the week
60. Set with GregorianCalendar.YEAR, MONTH and DATE
61. Determine if an hour is between an interval
62. Parse a String to obtain a Date/GregorianCalendar object
63. Try month in a leap year
64. Determining If a Year Is a Leap Year
65. Determining the Day-of-Week for a Particular Date
66. Subtract 30 days from the calendar
67. Date Format Test Date Format Test
68. Date and time with month
69. Date and time with day and month fully spelled-out
70. Formatting the Time Using a Custom Format
71. Convert string date to long value
72. Display date with a short day and month name
73. Convert Date to String
74. Validate a date Using DateFormat
75. Get the day name
76. Use the SimpleDateFormat from the java.text package
77. Formatting date with full day and month name and show time up to milliseconds with AM/PM
78. Getting the Current Time
79. Output current time: %tc
80. Get day of week
81. Convert milliseconds value to date
82. Calculate the age
83. Format a duration in ms into a string as "Days,Hours,minutes and seconds"
84. Formatting Symbols for SimpleDateFormat
85. Express a duration in term of HH:MM:SS
86. Match DateMatch Date
87. Checks if two calendar objects represent the same local time.
88. Checks if two date objects are on the same day ignoring time
89. Checks if two date objects represent the same instant in time
90. Calendar Comparator
91. Calendar To String
92. Formatter that caches formatted date information
93. Date Format Cache.
94. Date and time formatting utilities and constants.
95. Formatting dates into Strings.
96. Monitored GregorianCalendar
97. RFC date format
98. Utilities for java.util.Date
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.