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

x
?
Solved

Date value

Posted on 2005-05-16
7
Medium Priority
?
203 Views
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
0
Comment
Question by:letsbedecent
  • 5
7 Comments
 
LVL 29

Assisted Solution

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

Author Comment

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

Accepted Solution

by:
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)


0
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

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

Expert Comment

by:bloodredsun
ID: 14011404
imports are:

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

Expert Comment

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

Expert Comment

by:bloodredsun
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 )      ;
      }
}
--------------
0

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