Question

I'm getting lost with the following problem and I'm here because I need your assistance. Please suppose we have what's below:
1) A server which send date that is guaranteed to be in UTC and that accept date in UTC format
2) A setting in the application which allow the user to set a custom timezone ( the server pass the offset (in milliseconds) for this setting at the user login with no information about DST offset)
3) The OS timezone used by AS3 when it creates a new Date
It is required to convert the UTC date coming from the server from UTC to application's timezone and vice-versa.
I've written the following function to achieved what stated above but it seems to be wrong

public function convertUtcToLoc( date: Date, userOffsetMs: Number ): Date {
    var result:Date = null;
    if( null != date && ! isNaN( userOffsetMs ) ) {
        result = new Date();
        result.setTime( date.getTime() );
        result.setTime( result.getTime() - ( userOffsetMs + result.getTimezoneOffset() * 60000 ) );
    }
    return( result );
}

Of course I'd need to go back and fort so function convertLocToUtc must be arranged as well.
Does the code here make sense?
Any help is appreciated.
Thanks in advance
All the best

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top