Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8598945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:16:43+00:00 2026-06-12T01:16:43+00:00

Is it possible that i can get todays date , rather than time ??

  • 0

Is it possible that i can get todays date , rather than time ??

This is my code

public static void main(String args[]) throws ParseException{   
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    Calendar calendar = Calendar.getInstance();
    Date today = calendar.getTime();

}

Why is todays date is shown as before date ??

public class Ravi {

    public static void main(String args[]) throws ParseException {

        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date date = new Date();
        System.out.println("Todays Date"+dateFormat.format(date));


        List currentObject = new ArrayList();

        currentObject.add("2012-09-27");

        Date ExpDate = dateFormat.parse((String) currentObject.get(0));

        System.out.println("ddd"+ExpDate);

        if (ExpDate.before(date)) {
            System.out.println("true");
        }

        else {
            System.out.println("false");
        }

    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T01:16:45+00:00Added an answer on June 12, 2026 at 1:16 am

    Because Date is always the full current time e.g. 2012.09.27 12:45:23

    Whilst your new Formated date is 2012.09.27 00:00:00 therefor the output is correct.

    If you want to get false you will need to set hours, minutes and seconds to 0.

    Using Calendar:

    DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
    Calendar cal = Calendar.getInstance();
    System.out.println(dateFormat.format(cal.getTime()));
    

    Using Date:

    DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
    Date date = new Date();
    System.out.println(dateFormat.format(date));
    

    Comparing Dates with Calendar:

    Calendar old = Calendar.getInstance();
    
    old.set(Calendar.YEAR, 2011);
    
    Calendar now = Calendar.getInstance();
    
    old.before(now));
    

    Note you may want to set Hours Minutes and Seconds to 0.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Is there a standard date/time format that can be passed on a
How is it possible that following code even compiles? As far as I can
It's possible that this question has already been asked, but I can't seem to
Is it possible to create a custom configuration file (other than app.config) that can
Possible Duplicate: How to Get time difference in iPhone I´m getting date and time
What are the possible errors that can occur during memory allocation using malloc except
I am trying to learn about all possible conditionals that can be used on
Without help from additional container (like vector), is it possible that I can make
Possible Duplicate: Is there a tool that can display a SVN repository visually (
Is it possible to create a library that can be consumed from .Net 2.0

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.