[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Date value

Posted on 2005-05-16
Medium Priority
Last Modified: 2010-03-31
Hi all,

       I need to create a new date with a value of april 20th 2004. How do i do that....  new Date(int,int,int) is depricated, so how can i do this

Thank you
Question by:letsbedecent
  • 5
LVL 29

Assisted Solution

bloodredsun earned 1000 total points
ID: 14011368
   Calendar myDate= new GregorianCalendar(2004, Calendar.APRIL, 25);
    Date date = myDate.getTime();

Author Comment

ID: 14011380
What all should be imported to get this working ?
LVL 86

Accepted Solution

CEHJ earned 1000 total points
ID: 14011388
I think i've covered this in your other question. There are two ways:

1. Use a Calendar
2. Use a DateFormat

Here's 2:

DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
Date d = df.parse("20/04/2004");

(You need to catch exceptions)

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

LVL 29

Expert Comment

ID: 14011397
Oops, change the 25 to 20, but I'm sure you get the idea!
LVL 29

Expert Comment

ID: 14011404
imports are:

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
LVL 29

Expert Comment

ID: 14011413
or just do:
import java.util.*;
LVL 29

Expert Comment

ID: 14011540
Here's a working example:

package examples;

import java.util.*;

public class MyDate {
      public static void main(String[] args){
            Calendar mydate= new GregorianCalendar(2004, Calendar.APRIL, 20);
            Date date = mydate.getTime();
            System.out.println( "Date is " + date )      ;

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses
Course of the Month19 days, 3 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question