• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 251
  • Last Modified:

save Calendar in file

I am creating employee objects.  The requirement is
to save an employee record date info a  Calendar field.

No, problem.  Works great.

But how do I save it to a file?  None of the getInstance methods
seem to have all the args required to recreate an identical
Calendar object.

For now I just pulling out the time and saving that.

How do you do it?
0
hank1
Asked:
hank1
  • 3
  • 2
1 Solution
 
objectsCommented:
To create a Calendar instance from a Date instance you would use:

Calendar cal = Calendar.getInstance();
cal.setTime(date);
0
 
hank1Author Commented:


long calTime = calender.getTime()

write/read calTime to file

Calendar cal = Calendar.getInstance();
Date date = new Date(calTime);
cal.setTime(date);


Now  have an EXACT copy of the original Calendar object...... right?

Doesn't sound right.  what if they spin this up in India?  Don't you have
to set some local things?
0
 
objectsCommented:
Timezone details are associated with the Calendar instance, so if its run in another timezone the date will be adjusted accordingly.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
hank1Author Commented:
So, it will show that the record was created at, say,
5am, Monday April 24, 2005, no matter where you open it
and use it?  Seems this would work.  Time is time assuming
the time you use is gmt.

thanks
0
 
objectsCommented:
No, the time displayed (if using the Calendar) would be the time in that timezone.
You are storing the time without timezone (effectively GMT)
0
 
aozarovCommented:
>> long calTime = calender.getTime()
This returns java.util.Date and not time in milliseconds, I assume you meant calender.getTimeInMillis() or calendar.getTime().getTime()
saving calTime to a file will not be good if you move that value to a different timezone because calTime will
contain "number of milliseconds since January 1, 1970, 00:00:00 GMT" which will include both your timezone offset
as well as daylight saving offset. you probably want to save that value - timezone offset and and - daylight saving factor
which is basically converting your time into GMT time. When you applicatin deals with multiple timezone it is always good to store
your time in GMT (and that applies also to the date stored in your DB).
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now