vipul bondugula wrote:and the output object must be Date and not String.
We're all here to learn, so when responding to others, please focus on helping them discover their own solutions, instead of simply providing answers.
If you're talking about output (for display on the screen or wherever), then you ARE talking about String output. So, why should the output object NOT be a String?
vipul bondugula wrote:
i have to set the formateed Date ouptut to a Pojo object which has date of birth field of type Date and insert into database.
Do not wait to strike till the iron is hot; but make it hot by striking....
vipul bondugula wrote:i have a requirement. convert Date object to formatted Date object.
and the output object must be Date and not String.
vipul bondugula wrote:Actually the Date is inserted in the below format..
Thu Apr 05 11:28:32 GMT+05:30 2012
I want date to be in dd/MMM/yyyy format..
Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)
Jesper de Jong wrote:
vipul bondugula wrote:i have a requirement. convert Date object to formatted Date object.
and the output object must be Date and not String.
What you want is impossible. Date objects do not have a format by themselves. A "formatted Date object" does not exist.
When you print a Date object, you have to convert it to a string, and you do that by formatting it. But the format is a property of the SimpleDateFormat object that you use, not of the Date object itself. A Date is just a Date. It doesn't have a format by itself.
Anayonkar Shivalkar wrote:
vipul bondugula wrote:Actually the Date is inserted in the below format..
Thu Apr 05 11:28:32 GMT+05:30 2012
I want date to be in dd/MMM/yyyy format..
Again, please check last reply by Maneesh Godbole. To me, that approach seems the most practical one.
Store the date in DB as date itself (i.e. in whatever format db stores it) and while displaying it, just forma it. That way, you can still do date related operations at db level.
If you store date as string, what format will you choose? And what if that format changes in future? And how will you do date related operation (say to query data which went after jan 2012 or something like that?)
I hope this helps.
Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)
vipul bondugula wrote:Hi Friends,
i have a requirement. convert Date object to formatted Date object.
i mean
output will be Thu Apr 05 11:28:32 GMT+05:30 2012..
i want output to be like 05/APR/2012.
and the output object must be Date and not String.
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|