aspose file tools*
The moose likes Beginning Java and the fly likes convert the Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "convert the "Mon Oct 11 00:00:00 IST 2012" into a Date object" Watch "convert the "Mon Oct 11 00:00:00 IST 2012" into a Date object" New topic
Author

convert the "Mon Oct 11 00:00:00 IST 2012" into a Date object

sneha patil
Greenhorn

Joined: Feb 15, 2012
Posts: 15
I want to convert the "Mon Oct 11 00:00:00 IST 2012" into a Date object in yy-MM-dd format ,please help me out....
Thanks...
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4490
    
    8

I'd suggest looking at the SimpleDateFormat class - that can parse most formatted date strings into a Date object.

One thing I'd like to point out, though: there's no such thing as a "Date object in yy-MM-dd format". Date objects don't have a format. What you would want to do is convert the original string to a Date object, and then, when you need to display it somewhere, convert it back to a string in whatever format you want. You can do this with another SimpleDateFormat object matching the required output format.
sneha patil
Greenhorn

Joined: Feb 15, 2012
Posts: 15
Thanks for reply...
when i parsed string,it giving parsing error....
can you give me example so that i can get better idea??

Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

sneha patil wrote:Thanks for reply...
when i parsed string,it giving parsing error....
can you give me example so that i can get better idea??



It's hard to guide you toward fixing your code if you don't show that code.

I will note, however, that if you currently have a String representing a date in one particular format, and you want to change it to a String representing a date in a different format, you will need two DateFormat objects.
sneha patil
Greenhorn

Joined: Feb 15, 2012
Posts: 15


now am getting new date in yy-MM-dd format but as a string...and i want this as a date object..
please help....
Neeraj Dhiman
Ranch Hand

Joined: Dec 19, 2011
Posts: 66

try this
Date = newDateFormat.parse("your date in String formate");
Hope this will work for you..


Correct Me if i am wrong
sneha patil
Greenhorn

Joined: Feb 15, 2012
Posts: 15
Thanks for reply neeraj..
I tried ..but again i am getting date in Mon Oct 11 00:00:00 IST 2012 format...
Christian Kindler
Greenhorn

Joined: Apr 16, 2009
Posts: 18
As Matthew already said above, a Date object has no format. The toString() does some formatted output for you, but it will be always the same. If you want to have your Date as a String in certain format, you have to use a DateFormat again.
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4490
    
    8

sneha patil wrote:..and i want this as a date object..


You already have it as a Date object. Your first line of code is this:
This means you've already got a Date object. As I said, this doesn't have any formatting. If you print it out it will use the toString() method, and that uses a default format. But the Date object itself has no format at all.

So you should just use this Date object until you need to print it out somewhere. At this point, you decide what format you want, and you use a SimpleDateFormat to convert it to a String using that format:

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40034
    
  28
How on earth are you getting that date past it? 11th October this year is a Thursday.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: convert the "Mon Oct 11 00:00:00 IST 2012" into a Date object