Date issue in Client(Flex) and Serverside(JAVA) issue - apache-flex

I have a date porblem in flex applications.
while submit the date in flex applcation (28/09/2010 10:00:00 AM) as a string, the date is cobnverted in to Date object inserver side and displayig the result.
But i install the server in other location (Ex:- USA) .Now i am passing the date from india(28/09/2010 10:00:00 AM) But the date in the USA is different. How to convert the date? Conversion should be happen in client side or server side? How the server knows the date which is given by client is the current date?
Thanks,
Ravi

You can save the date as UTC ( universal time ) on the server , and when retrieved on the client use the Date class timeZoneOffset property to set the date to the client's current location

Related

Application gets different date format

The server where I have deployed my ASP.NET application uses the date format mm/dd/yyyy. So it is expected that when accessing the application, the user should see the date in a calendar control formatted as mm/dd/yyyy.
But on some other machine it shows the date format as dd-mm-yyyy, and with this date format the SQL query crashes with a datetime conversion error.
Can you help me with this? Why does the date format change with the machine?
Thanks.
it changes because of the culture set on the machine, but you can always format the date like this:
string.Format("{0:MM/dd/yyyy}", datevalue);

asp.net + Testing timezone

I am try storing my date values in UTC format into my SQL Server DB and then convert them to local time for displaying, seem to work fine, I can see that my DB date values stored are different(I presume it's converted to UTC already), retrieving it and display is also accurate until I try to test a different timezone by changing it in the Date and Time option(right bottom of Windows time settings in the task bar) so to "migrate" myself. Apparently, the dates still remain as I am in my own country even though the timezone which I changed to has a 3 hrs difference.
Can somehow please advice on a way to test the date display on a different timezone?
Thanks.
Storing date values to SQL Server:
DateTime dateFrom = DateTime.Parse(startDateTime).ToUniversalTime();
DateTime dateTo = DateTime.Parse(endDateTime).ToUniversalTime();
parameters.Add(new SqlParameter("#StartDateTime", dateFrom));
parameters.Add(new SqlParameter("#EndDateTime", dateTo));
Retrive from DB and Display:
DateTime date = DateTime.UtcNow.ToLocalTime();
date = DateTime.Parse(dr["StartDateTime"].ToString()).ToLocalTime();
litDateTimeFrom.Text = date.ToString("dd MMM yy hh:mm tt");
date = DateTime.Parse(dr["EndDateTime"].ToString()).ToLocalTime();
litDateTimeTo.Text = date.ToString("dd MMM yy hh:mm tt");
First thing, I am assuming that you have changed time zone information on the server machine (because that is what will be used in ToLocalTime method). If not then that's what you need to do first for testing.
Secondly, have you tried restarting IIS (or your web application) after changing the system time zone? That is necessary because time-zone information could have been cached within .NET framework (in TimeZoneInfo class).
Said all that, to me, this does not make sense. Typically, time-zone information need to flow from user (client) machine because you want to show user local time (as relevant to his time-zone). So it would mean that you need to figure out the current user's time zone based on a) culture info from browser or b) what is stored in his profile data (perhaps country or actual time-zone) c) similar scheme. Once, user time-zone is known, you can use
TimeZoneInfo class to convert UTC time to corresponding local time.

asp.net now() function with different time zones

I will be entering some values into a database based on input from users. One value will be the date and time of the input.
I'm not sure how this works at all, but a user from e.g. New York enters some data and the website is hosted in the UK...what time will be stored?
Up until now I had been using the "now()" function to record the date and time, but just occured to me that this could happen! What else should I use?
Thanks,
UTC, works in any time zone, you can either save all dates in your storage as UTC or use proper type that includes time zone data, for example in SQL 2008 you can use datetimeoffset

how to set local time based on time zone in asp.net

Hi i am developing a website where user will select the timezone from a dropdown. And in my database the datetime are stored in UTC format. How i can display his profile all other things as per timezone selected by user.
You can store the timezone offset for the user and apply that to the UTC time each time you want show the date/time.

how to store datetime as per internationalization

I am having a project which will have country dropdown at the top to select countries. For example USA, India and Hong Kong. Depends on the country selection several features will be enabled or disabled.
In project I am having base country by default for example India. So whenever any user will come. I want to store its login datetime as per Indian standard time regardless user is from Hong Kong, USA or India. My webserver is hosted in USA.
Is that possible?
What you want to do is store any datetime value as UTC. Which means storing as a time zone independent value.
You can either set some sort of insert trigger in your MS-SQL server (I assume you use MS-SQL because of the asp.net part). There you determine the UTC time like this.
`-- MS SQL (use instead of GETDATE())
DECLARE #currentTime datetime
SET #currentTime = GETUTCDATE()`
If you want to do it in code just use UtcTimeNow to access the UTC time.
// C# (use instead of DateTime.Now)
DateTime currentTime = DateTime.UtcNow;
If you want you can always convert the UTC time to any given local time. By using the TimeZoneInfo class.
That way you have the right time in your database (UTC) and can convert it to the appropriate time for the User.
The most important part when dealing with times and timezones is to store it as UTC. That way it's can be transported and compared easily.
If you save your time in unixtime, you can have a field in the user table called offset. Where it's value is how much the system needs to offset the time.
Then you'd just fetch that variable and save that as a session value or something similar. And use that to offset the datetime in the system.
For example. Hong Kong is +8 hours from GMT. Now in GMT Unixtime is: 1242293400 (9:30 am). 8 hours is 28800 seconds. You would then store this value in your server. So the time would be 1242322200 (5:30 pm same day)
IF you are using SQL Server 2008, look at the new datetime datatypes which allow you to store the offset/timezone as well.

Resources