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 6992931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:41:56+00:00 2026-05-27T19:41:56+00:00

I want to get a new Date object with a SimpleDateFormat applied to it.

  • 0

I want to get a new Date object with a SimpleDateFormat applied to it. I would like to do something like:

SimpleDateFormat myFormat = new SimpleDateFormat("dd MMM yyyy kkmm");
Date today = new Date();
today = myFormat.format(today);

I can’t do this, because today is a Date, and format returns a String. I also have tried:

Date today;
SimpleDateFormat myFormat = new SimpleDateFormat("dd MMM yyyy kkmm");
try{
    today = myFormat.parse((new Date()).toString());
}catch(Exception e){

}

This isn’t a good solution, because when I try to use today elsewhere Java complains that today may not have been instantiated. What is a good way to change the format of a Date object (while still keeping it a Date object, and not turning it to a string)?

  • 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-05-27T19:41:56+00:00Added an answer on May 27, 2026 at 7:41 pm

    You are looking at Format and Date wrongly.

    • Date does not contain format. Date is just a class containing date info like date, month, hours, sec etc.
    • SimpleDateFormat is the one which tells you the string representation of Date. But there is no date associated with it.

    So the idea is when you have to display date or have to store date in some string representation, you will use SimpleDateFormat and pass it the date you want string representation for.

    One benefit of doing this way is that, I can use same Date object and can show two different string representations (using two different instances of SimpleDateFormat). And also viceversa, having defined one SimpleDateFormat instance, I can format multiple dates.

    Edit:

    Now if you want to strip some info from the date. Use

    Calendar rightNow = Calendar.getInstance();
    Calendar cal = new GregorianCalendar(
       rightNow.get(YEAR),
       rightNow.get(MONTH),
       rightNow.get(DAY_OF_MONTH));
    Date now = cal.getTime();
    

    There are other good soln like JodaTime

    Ref:

    GregorianCalendar
    Calendar
    Joda Time

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

Sidebar

Related Questions

I want to do something like var date = new Date(); var pretime =
I want to add days to a date to get a new date in
I want to get the date object text content and Team 1. But Team
Is it possible to create a new Date() object to get the current date,
I create new desktop with CreateDesktop and want to get it's DC & RC.
I am new to iPhone programming. I want to get the height and width
I want to get the difference between two Java Date objects. I've used Joda-Time
I have a Java date object: Date currentDate = new Date(); This will give
I want to set all DateTime properties of my object to a default date.
I'm using Java's java.util.Date class in Scala and want to compare a Date object

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.