This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Java in General and the fly likes Displaying the Date - Issue Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Displaying the Date - Issue " Watch "Displaying the Date - Issue " New topic
Author

Displaying the Date - Issue

Viswas majrekar
Greenhorn

Joined: Dec 20, 2008
Posts: 5
Hi Eveyone,

Can you please anyone give me solution for this below issue.

I am trying to print the System current date.

In java code it is printing correct date, while displaying on the browser TextFiled it is showing the previous date.


For this i used the code like

String Date_Format = "MM-dd-yyyy";

Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat(Date_Format);

Date date=sdf.parse(sdf.format(cal.getTime()));

Jesper de Jong
Java Cowboy
Bartender

Joined: Aug 16, 2005
Posts: 12953
    
    3

Viswas majrekar wrote:Date date=sdf.parse(sdf.format(cal.getTime()));

Why are you formatting and then immediately parsing the date again? If you need a Date object, just do:

If you need to convert a Date object to a String, format it:

parse() does the opposite of format() - it converts a String to a Date object. First formatting and then immediately parsing a Date object effectively does nothing.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Displaying the Date - Issue
 
Similar Threads
converting dateformat compatible to oracle date
JSP and Access - Date function problems
Problem in Changing Timezone (URGENT)
How to get Date Format of a System??
Problem with date insertion in MySQL