• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Convert Calendar object to Date object

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Friends

i am stuck in a issue for which i need your help.
i am trying to do a conversion between Date object to Calendar object.
Till now i was successful in converting the Date object to Calendar object.
below is the sample code to do that

String dtStr="2007/05/24";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
Date dt = sdf.parse(dtStr);
Calendar cal = Calendar.getInstance();
cal.setTime(dt);

i am getting the output in following format
Thu May 24 00:00:00 IST 2007
and i am passing this Calendar object to a method XYZ(cal).

Now the problem is the conversion between Calendar object back to the Date object.
In another method PQR() i have to convert the Calendar object(cal in this case) to Date Object.
I am facing a problem to that this conversion.I have to convert this Calendar object back to Date object and get the Date object in the same manner as Thu May 24 00:00:00 IST 2007
Please can anybody provide me a piece of code to do this conversion .
it would be a great help for me as i am stuck with this issue for a long time.

Thanks & Regards
Vikeng
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you tried Calendar.getTime() ?
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it's most helpful if you can show us some code that almost works and explain just how it doesn't do what you want. Where are you stuck? Are you able to construct a new Date from the Calendar's time? Does it look like the right date? In the right format?
 
Space seems cool in the movies, but once you get out there, it is super boring. Now for a fascinating tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic