views:

87

answers:

3

Hello.

I am using a JQuery plugin to render a calendar (http://arshaw.com/fullcalendar/). Problem is that the dates are one hour ahead. I have tried looking into the files to find out where this happens.

Can it be something with day light savings? I am pretty clueless. The dates from the database is correct, but once they are converted to a UNIX timestamp they are missing one hour.

I use this to convert my date to timestamp.

private double ConvertToTimestamp(DateTime value)
{
    //create Timespan by subtracting the value provided from
    //the Unix Epoch
    var date = new DateTime(1970, 1, 1, 0, 0, 0, 0);

    TimeSpan span = (value - date.ToLocalTime());

    //return the total seconds (which is a UNIX timestamp)
    return (double)span.TotalSeconds;
}

But i believe its not where the problems lies.

Thank you.

+1  A: 

Is it possible that you live in a part of the world that observes Daylight Savings Time? That would explain why your dates are an hour ahead. Try skipping ahead to December and adding a few dates. Are they still an hour ahead?

theycallmemorty
Exactly. How can I code this behavior? :-)
meep
@meep: I think the best thing to do would be to modify the start and end times of your events in your server side code. Unfortunately, I'm not a C# expert so I don't know how to do that. :/
theycallmemorty
A: 

I just experienced a similar issue when moving from my dev box to Amazon EC2 for staging... The Regional Settings on my Amazon instance were set to US West Coast, not my timezone (Sydney, Australia).

Changing this, and then updating the locales of the built in accounts (Network Instance etc) resolved my problems with the dates being rendered incorrectly.

Boycs
+1  A: 

I have had a similar problem and solved it with: function _changeToLocal (localDate) { return new Date( localDate.getFullYear(), localDate.getMonth(), localDate.getDate(), localDate.getHours(), localDate.getMinutes() + localDate.getTimezoneOffset()); } assuming it's a TimeZone related problem. Günter