i have WebService in the PC
and i get date & time in dd/mm/yyyy and on another PC in mm/dd/yyyy
i have any Windows-CE mobile that connect to this PC
how to Synchronize date & time between PC and mobile ?
(i need that the PC date & time will be in the monile)
thank's in advance
Your web service should expose the date and time in a standard format (e.g. ISO-8601). If your web method is declared to return a DateTime, this should happen automatically - the situation you've described should only occur if you're explicitly doing something like:
return DateTime.UtcNow.ToString("d");
... don't do that, basically.
Convert the date of your Smartphone to ISO format (i.e. yyyy-mm-dd) then send it to your PC and convert it there from yyyy-mm-dd to mm/dd/yyyy
Related
I have a database that is filled with log data by an external program.
One column is a timestamp of type DateTime.
Depending on the external programs host settings of time format, it either writes into the database using 24h or 12h format with AM/PM.
This query I used to get the time (on the same machine, but two database files from different external devices):
SELECT Time FROM tabData
The output (from a machine with AM/PM time setting)
2017-05-31 8:52:26 AM
and another (from a machine with 24h time setting)
2017-05-31 08:52:26
Why does the database datetime keep that 12h mode with AM/PM? Can I somehow change the format of the database datetime by SQL?
I further want to read these data into a DataTable in C#, and I'd prefer a SQL statement to read any given datetime as 24 hour datetime.
If SQLite is anything like MSSQL and Oracle, it doesn't have a Format for datetime except for its internal storage format that you shouldn't need to know anything about. The format you see only shows up when you use a Client to query that date, and then the actual format depends on the client you use, for instance general time settings chosen on the client machine.
We currently are trying to implement time zone management in our application. Our server is in India. We will be saving all entries in server time. But when coming to the client side, we need to show the data in the client time. So I came into this conclusion that getting the client time zone from the front end and converting the server time to client time using the code below in the database will solve the problem.
DECLARE #ServerTime DATETIMEOFFSET(7) = '2015-02-21 22:06:08.6862774 +05:30' -- My server time
DECLARE #ClientTime DATETIMEOFFSET(7) = '2015-02-21 12:38:09.5421899 -04:00' -- My Client Time
SELECT SWITCHOFFSET(#ServerTime, DATEPART(TZ, #ClientTime))
My question is
Is there any better option?
Can this be done from the front end (C#)?
Last and most important question is:
How can I manage if the client machine is in daylight saving?
Any support will be appreciated.
You can do this in a much simpler way in .NET, since .NET has some "automatic" mechanisms to deal with this.
For example: if your client app invokes a web service and sends as argument a DateTime in local time (date.Kind == DateTimeKind.Local) the date is serialized with the offset ("2015-08-19T14:21+01:00") on the server side the date will be deserialized and converted to the server's local time. For instance, using the date above and if the server is in UTC the DateTime object would have the value "2015-08-19 13:21:00" (however you will not have any information about the timezone where the client is and where the date was created). If the date is sent again to the client the inverse conversion is made and the date will have the original value on the client.
This way the server will always process dates using local time and the client will always process dates in local time, although they do not know the timezone of each other.
I believe this mechanism does not deal well with ancient past dates because of daylight saving time, this is probably being limited by the information windows has about daylight saving time (as an example for the timezone "E. South America Standard Time" windows 8 only has DST information from 2006 to 2040 meaning that dates previous to 2006 could be misunderstood).
Having said that, I believe the best solution to deal with different timezones is to use UTC and convert to local time when displaying the date to the user, or always use DateTimeOffset instead of DateTime (DateTimeOffset also has information about the date timezone).
You can use:
SELECT CONVERT(datetime,'2019-03-11 11:59:59')
AT TIME ZONE 'UTC'
AT TIME ZONE 'US Eastern Standard Time';
It also handles daylight saving time.
While it is better to do this in client code, if you decide you need to work with time zones directly in SQL Server, you can now use my SQL Server Time Zone Support project.
Example:
SELECT Tzdb.UtcToLocal('2015-07-01 00:00:00', 'America/Los_Angeles')
In a web application, I am passing datetime without formatting it in a XML response, just item.Date (DateTime datatype) is put in code.
No formatting is done. When I run the local server it returns the date in MM/DD/YYYY format and in live environment DD/MM/YYYY. Why this change is happening?
I checked on database collation and OS settings. Live environment had English (Singapore) in regional settings. However after changing local servers to English (Singapore) still live environment DateTime format is not being produced locally.
Collation:
In Live Environment - Latin1_General_CI_AI
In Local Servers - SQL_Latin1_General_CP1_CI_AS
What could be the reason? how to resolve this rather than doing formatting in XML?
Update
As suspected, Issue is with collation, regenerated the issue locally after creating DB with collation in live environment.
Windows stores Date/Time settings per user. If IIS is running as LocalSystem, then you'll need to change the settings of the Default user:
In regedit, go here and set the appropriate values up for the locale and format that you want.
HKEY_USERS\.DEFAULT\Control Panel\International
That said, handling dates and times types under the assumption of any given format is A Really Bad Idea.
If you need date/time in a specific format for display, interop or whatever you should format the date time appropriately with one of the available string formats.
I have an application in C# where I want to show the Start Date from the server... I mean the real date since the server is running....
The goal is to know if the server went down in any moment.
I´m not sure but it has to be any class in C# to be able to get this datetime from the server...
if you execute in the console "net statistics server"... you display exactly the time i mean...
any idea`?
Thanks in advance!
DateTime start =
DateTime.Now -
TimeSpan.FromMilliseconds(System.Environment.TickCount);
I've developed an MVC 4 with C# application which I've deployed using Windows Azure to their datacenter in Virginia. I log user activity in my application recording both the username and the time that an activity was initiated. The time recorded needs to be converted to Fiji Standard Time. Based on what I have found online I wrote an extension method to help achieve this functionality.
public static DateTime ToFijiTime(this DateTime datetime)
{
datetime = DateTime.SpecifyKind(datetime, DateTimeKind.Utc);
TimeZoneInfo tz = TimeZoneInfo.FindSystemTimeZoneById("Fiji Standard Time");
DateTime MyDateTime = TimeZoneInfo.ConvertTime(datetime, tz);
return TimeZoneInfo.ConvertTimeToUtc(MyDateTime, tz);
}
However this doesn't really work well once it's deployed. I get the right date and almost the right time. For some reason it always gives the time as an "am" time. For example if the time should be 2/04/2013 6:30:19 PM (Fiji Standard Time)The time recorded is actually 2/04/2013 6:30:19 AM (Fiji Standard Time) but times that are in the morning like2/04/2013 1:30:19 AM are saved correctly. Can anyone please tell me what's wrong with my code?
Store the users timezone server side then,
Use following:
#TimeZoneInfo.ConvertTimeFromUtc(Model.CreatedOn, TimeZoneInfo.FindSystemTimeZoneById("E. US Standard Time"))
Also refer this :
Convert UTC/GMT time to local time