How to set time zone to frecnh zone + windows ce - compact-framework

I need to set my timezone in my mobile device to french zone in c# (windows embedded ce)
how can I do this please?

You can use this library to ease your development: https://opennetcf.codeplex.com/
I'm using it and setting the time zone through the following objects: TimeZoneCollection, TimeZoneInformation, DateTimeHelper.

You can not set the TimeZone to a city/location, you can only set the DST data.
See my post here: http://community.intermec.com/t5/Device-Management/change-Time-Zone-with-xml/m-p/17007/highlight/true#M1023
============================================================
You can not set the name of a TimeZone using the registry!
You only can set the Offset and DST values. The clock panel then uses a matching entry.
In the registry, the values for "GMT-7 (Mountain US)" and "GMT-7 (Arizona)" are nearly the same
[HKEY_LOCAL_MACHINE\Software\Microsoft\Clock]
"AppInfo"=hex(3):01,00,00,00,80,01,00,00,0f,00,00,00,00,00,00,00,00,00,00,00,3a,01,00,00,69,00,00,00,00,00,00,00,01,00,00,00
"AppState"=hex(3):11
"AutoDST"=dword:00000000
"GMT_OFFSET"=dword:000001A4
"HomeDST"=dword:00000000
"NetworkTimeNotifyUser"=dword:00000001
"NetworkTimeSync"=dword:00000001
"TZIndex"=dword:00000004
(see also http://peterfoot.net/HomeAndVisitingClocksInProfessionalEdition.aspx)
and
[HKEY_LOCAL_MACHINE\Software\Microsoft\Clock]
"AppInfo"=hex(3):01,00,00,00,80,01,00,00,0a,00,00,00,00,00,00,00,01,00,00,00,3a,01,00,00,69,00,00,00,00,00,00,00,01,00,00,00
"AppState"=hex(3):11
"AutoDST"=dword:00000000
"GMT_OFFSET"=dword:000001A4
"HomeDST"=dword:00000001
"NetworkTimeNotifyUser"=dword:00000001
"NetworkTimeSync"=dword:00000001
"TZIndex"=dword:00000004
But, as you can see, there is no Name String of the time zone.
[HKEY_LOCAL_MACHINE\Time]
"TimeZoneInformation"=hex(3):a4,01,00,00,55,00,53,00,20,00,4d,00,6f,00,75,00,6e,00,74,00,61,00,69,00,6e,00,20,00,53,00,74,00,61,00,6e,00,64,00,61,00,72,00,64,00,20,00,54,00,69,00,6d,00,65,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,55,00,53,00,20,00,4d,00,6f,00,75,00,6e,00,74,00,61,00,69,00,6e,00,20,00,44,00,61,00,79,00,6c,00,69,00,67,00,68,00,74,00,20,00,54,00,69,00,6d,00,65,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,c4,ff,ff,ff
and
[HKEY_LOCAL_MACHINE\Time]
"TimeZoneInformation"=hex(3):a4,01,00,00,4d,00,6f,00,75,00,6e,00,74,00,61,00,69,00,6e,00,20,00,53,00,74,00,61,00,6e,00,64,00,61,00,72,00,64,00,20,00,54,00,69,00,6d,00,65,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,0b,00,00,00,01,00,02,00,00,00,00,00,00,00,00,00,00,00,4d,00,6f,00,75,00,6e,00,74,00,61,00,69,00,6e,00,20,00,44,00,61,00,79,00,6c,00,69,00,67,00,68,00,74,00,20,00,54,00,69,00,6d,00,65,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,03,00,00,00,02,00,02,00,00,00,00,00,00,00,c4,ff,ff,ff
These are the TimeZoneInformations (the TIME_ZONE_INFORMATION structure).
Clipboard02.gif
You may query the timezone city db as done in the attached file (TZ-cities.txt).
The attached tool (timezoneset.exe) can be used to change the offset of the current active timezone.
The time zone informations for Prague and Berlin are the same:
index: 95
short name: GMT+1 Prague,Budapest
name: Central Europe Standard Time
GMT offset: -60
dst name: Central Europe Daylight Time
DST offset: 0
...
index: 110
short name: GMT+1 Berlin,Rome
name: W. Europe Standard Time
GMT offset: -60
dst name: W. Europe Daylight Time
DST offset: 0
except for the dst name.
It is no good idea to set timezone informations using the registry.

Related

Why does the code below return 4:14 PM instead of 3:14 PM?

I'm trying to convert a UTC to a CST by using the 'ConvertTimeFromUtc' method. However, the result is off by 1 hour compared to what I got when I try to convert it manually online.
StatusDatetime is 2017-06-05 21:14:39.6216795
TimeZoneInfo.ConvertTimeFromUtc(StatusDatetime.Value,
TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time")).ToString("hh:mm
tt")
Try using Central Daylight Time instead of Central Standard Time, as we are in daylight savings time.

VB difference between windows file hour and VB file hour

How to obtain the date from a file without the influence of windows time settings ?
I'm trying to read date file with VB but I obtain a difference between the time writes on file properties (WDT) and the time returns by VB (VBT), due to daylight saving time
If I read a file saved during winter time in summer, I have a difference of VBT = WDT+1h. And in the same case, if I read a file saved during summer in winter, I obtain a difference of VBT = WDT-1h.
You need to convert the DateTime(s) to UTC and compare those times. This is the time without any adjustment for daylight savings, etc.
There is an extension of the DateTime type ToUniversalTime that returns the UTC value:
https://msdn.microsoft.com/en-us/library/system.datetime.touniversaltime(v=vs.110).aspx
Example:
Dim currentDateTime = DateTime.Now
Debug.WriteLine(currentDateTime.ToString)
Debug.WriteLine(currentDateTime.ToUniversalTime.ToString)
Outputs on my machine (UK Time Zone +1h from UTC for British Summer Time)
15/04/2016 12:21:04
15/04/2016 11:21:04
Note that there is also a DateTime.UtcNow if you want the current system time directly in UTC

Tibco xpath daylight saving issue

Does anyone here knows how to solve the Tibco xpath daylight saving date issue.
The issue was we have one record 03/10/2013 02:00 parsed via Tibco mapping palette with following format (mm/dd/yyyy hh:mm). However, it got invalid date time error with above date. It worked with all other times, e.g. 03/10/2013 01:00, 03/10/2013 03:00, just not working with anytime between 03/10/2013 02:00 ~ 03/10/2013 02:59.
The current xpath we using parse-dateTime(format, string)
So, can xpath detect the daylight saving automatically with the inbound date format (mm/dd/yyyy hh:mm) and parse it?
Thanks so much.
James
Yes. The TIBCO function that parses dateTime does detect Day Light Saving.
I think you have two options to handle these cases in your engine.
Change the code to have a Java Code parse the dateTime. I am aware
that java correctly returns the time with 1 hour added in this case.
You should be able to do a TimeZone.getDefault() to get the server's
default TimeZone.
Change the java default timezone in the TRA - java.property.user.timezone in the designer.tra I suppose.
I have not tried these. :-)
I had the same problem with DST, trying to parse string 2014-03-30 02:00:00 which does not exist in italian timeZone.
Since the input date was perfectly legit (intended to be in GMT+0) I solved by forcing the timezone with this code. It should work with any other timezone as long as it doesn't support DST.
tib:parse-dateTime("yyyy-MM-dd HH:mm:ss Z"), concat($Start/root/dateTimeFrom, ' +0000')
Enable daylight in deployment.yaml (kubernetes)
- name: BW_JAVA_OPTS
value: "-Dbw.engine.enable.memory.saving.mode=true -Xms1024m -Xmx4096m"

Linking datetimes of events to their associated location timezone (TimeZone gem, ActiveSupport::TimeWithZone)

I beat my head against this for a day and a half before it finally all came together, partly because I was fundamentally misunderstanding some things because of my assumptions of how things should work, and so the results I was getting seemed so completely irrational and confusing that I was starting to think things must be horribly broken in the libraries. They weren't.
This thread is to share my question, and what worked, partly because it seems to me that a lot of times a datetime record should be tied to the localtime of its location, and a lot of times when applications behave strangely with respect to timezone changes I think it's because they don't do that. So here's how to do that.
The easy part was using the TimeZone gem to get the location's timezone (I already have the latitude/longitude from using the GMaps4Rails gem), as described here: Ruby gem for finding timezone of location
Initially, I hoped each datetime could have an intrinsic and persistent time zone, even after being saved and retrieved from the DB, since we only care about the local time zone for each event. For the unusual and rare case where the datetime was needed in other-than-local-zone, I could convert. But I guess that doesn't exist since MySQL seem to have no concept of timezone with its datetime, and just stores everything as a plain ol' date and time.
So, that's fine -- the DB stores in UTC and I must do the conversions each direction.
How? (See below.)
User enters a datetime (year, month, day, hour, min, sec) in the appropriate local time for the event location. To save this as the correct UTC time in your DB, and retrieve later retrieve it and use it with its correct timezone, here's the recipe:
You must first set Time.zone = timezone -- where timezone is a named timezone string, like "America/Toronto" (GeoKit/TimeZone style) or "Eastern Time (US & Canada)" (Rails 3 style):
1.9.3p200 :001 > Time.zone = "America/Toronto"
=> "America/Toronto"
Note that it is nontrivial to map between the GeoKit/TimeZone style and the Rails 3 style. There is some support for that, but many of the mappings that GeoKit returns are not in the Rails mappings, so I'm sticking with the GeoKit/TimeZone names because they seem to work just fine, and I don't need user-selectable timezones because I'm taking care of all of that automagically for the user using the locations.
Now you can parse and save your datetime variable using ActiveSupport::TimeWithZone, and it will be encoded properly using the Time.zone parameter:
1.9.3p200 :002 > t = Time.zone.local( 2012, 8, 1, 12, 0, 0 )
=> Wed, 01 Aug 2012 12:00:00 EDT -04:00
i.e. In my case, for my Event model with instance event:
event.start = Time.zone.local( year, month, day, hour, min, sec )
event.save
When the data is saved to the DB, it is in UTC: 2012-08-01 16:00:00.000000
(Simulated below with call to t.utc)
1.9.3p200 :003 > t = t.utc
=> 2012-08-01 16:00:00 UTC
1.9.3p200 :004 > t.zone
=> "UTC"
Now, when you read it back from the DB, you need to again use the TimeWithZone support to tell the DateTime what timezone it is in.
Note that the in_time_zone function does not change the underlying datetime variable's timezone:
1.9.3p200 :005 > t.in_time_zone( "America/Toronto" )
=> Wed, 01 Aug 2012 12:00:00 EDT -04:00
1.9.3p200 :006 > t
=> 2012-08-01 16:00:00 UTC
1.9.3p200 :007 > t.zone
=> "UTC"
so you really need to assign the function output back to your datetime variable:
1.9.3p200 :008 > t = t.in_time_zone( "America/Toronto" )
=> Wed, 01 Aug 2012 12:00:00 EDT -04:00
1.9.3p200 :009 > t
=> Wed, 01 Aug 2012 12:00:00 EDT -04:00
1.9.3p200 :010 > t.zone
=> "EDT"
Finally, a warning -- do not use t.time! It's output is completely useless and irrational, with the time and it's timezone out of sync:
1.9.3p200 :011 > t.time
=> 2012-08-01 12:00:00 UTC

Classic ASP - Server Time vs. Local Time

I have a Classic ASP application that I am working with date cut offs. My server resides in Central Time, but I am in Eastern time. What happens is my app thinks it is an hour earlier and my cut offs are an hour late. I am sure they would be 2 hours early if a user was in Pacific time.
What I am trying to figure out is if there is a way to either
tell the server to show me local time when you do a GetDate() on SQL or Now() in ASP
figure out some way to do an offset that I can run when the page first loads and use as needed.
I tried server side javascript, it returns Central Time too. Any help would be greatly appreciated!! Thanks in advance!
Dennis
UPDATE - 4/11/12 # 1:12pm:
I think that I found a work around for my application, but it would not work generically. I have geographic data for the location I am working with - zip code. I can grab the timezone from that - it would not fully work right for users in other timezones looking at the location, but it does not matter for my app since I just need to be focused on the end time for that location.
This is the other other way(s) I found were provided by JohnB below (specifically #4). thanks everyone. http://www.webmasterworld.com/forum47/600.htm (bottom)
EDIT
I tried server side javascript, it returns Central Time too.
Did you mean to say client side JavaScript? You definitely need to use client side script to get the user's device time (not server side script).
You should read this:
Daylight saving time and Timezone best practices
Primer on dealing with multiple time zones:
1) Make sure your database server is set to the correct Date/Time in its time zone. Properly account for Daylight Savings Time in its location. Set the server to do this automatically.
Configure automatic date and time synchronization on Windows Server 2008 R2
2) Create a table in your database with time zones and their offset from UTC (GMT).
Time zone
3) Always store Now() Date/Time in UTC. Every database vendor should have a UTC Date/Time Now() function (i.e. SYSUTCDATETIME() for SQL Server). This way all times are stored in a universal format agnostic to where the user happens to be sitting. Call Now() from your database, not the client, because mobile devices could be anywhere, but your database server stays in one spot.
Date and Time Data Types and Functions (Transact-SQL)
4) Have user input their local time zone and store it in your database.
5) When displaying Date/Time stored in UTC back to the user, convert the UTC Date/Time back to the user's time zone using the user's time zone offset. SQL Server makes this a little easier with datetimeoffset.
SQL Server How to persist and use a time across different time zones
The Death of DateTime?
6) If the user is setting an alarm, have them enter the trigger Date/Time in their local time zone. This way the user can change their local time zone if they move. Also, if time zone rules change you can just fix your time zone table (#2) and then the alarm will still trigger correctly. In your code, to test for alarm trigger, convert trigger time to UTC, and then compare against server time in UTC (i.e. SYSUTCDATETIME()).
7) Daylight Savings Time is tricky! (see 1st link)
In general, Time zone manipulation can't be done directly in classic ASP.
However, if you have full control of the server where the code is running, you can install a COM component written in a language that does have time zone support, then use that component from your classic ASP environment.
For example, you might write the following component in .NET with C#:
using System;
using System.Runtime.InteropServices;
namespace TimeZoneInfoCom
{
[ComVisible(true)]
[ClassInterface(ClassInterfaceType.AutoDispatch)]
[Guid("E0C70A94-352D-4C0B-8C2E-8066C88565C5")]
public class TimeZoneConverter
{
public DateTime NowInZone(string timeZoneId)
{
return TimeZoneInfo.ConvertTimeBySystemTimeZoneId(DateTime.UtcNow, timeZoneId);
}
public DateTime Convert(DateTime dateTime, string sourceZoneId, string targetZoneId)
{
TimeZoneInfo sourceTimeZone = TimeZoneInfo.FindSystemTimeZoneById(sourceZoneId);
TimeZoneInfo targetTimeZone = TimeZoneInfo.FindSystemTimeZoneById(targetZoneId);
return TimeZoneInfo.ConvertTime(dateTime, sourceTimeZone, targetTimeZone);
}
}
}
You would then compile this, copy the DLL to your server, and register it as a COM component (using RegAsm.exe).
Then you could call it in your Classic ASP page, like so:
<html>
<body>
Server Time: <%= Now() %><br>
<br>
<%
Dim tzconverter
Set tzconverter = Server.CreateObject("TimeZoneInfoCom.TimeZoneConverter")
%>
US Pacific Time: <%= tzconverter.NowInZone("Pacific Standard Time") %><br>
US Mountain Time: <%= tzconverter.NowInZone("Mountain Standard Time") %><br>
US Central Time: <%= tzconverter.NowInZone("Central Standard Time") %><br>
US Eastern Time: <%= tzconverter.NowInZone("Eastern Standard Time") %><br>
UTC: <%= tzconverter.NowInZone("UTC") %><br>
<br>
Conversion Example:
<%
Dim originalTime, convertedTime
originalTime = #12/31/2014 00:00:00#
convertedTime = tzconverter.Convert(originalTime, "UTC", "Tokyo Standard Time")
Response.Write(convertedTime)
%>
<%
' Don't forget to destroy the com object!
Set tzconverter = Nothing
%>
</body>
</html>
If you get an "ActiveX component can't create object" error, be sure that you have set "Enable 32-Bit Applications" to True in IIS, under the advanced settings for your application pool.
With regard to SQL Server - If you search, you may find a handful of posts showing ways you can manipulate time in SQL Server, through elaborate stored procedures that either have fixed offsets, fixed time zone rules, or rely on tables of time zone data. I usually advise against any of these approaches because they are too brittle.
Fixed offsets are bad because they don't account for daylight saving time.
Fixed rules are bad because time zone rules can (and do) change. Editing stored procs to keep up with these changes is too fragile (IMHO).
Maintaining tables of time zone data is a little better, but usually I find these tables to not be maintained well. If you go down this route, be sure to put a procedure in place for updating the tables periodically.
Getting the users time zone
http://www.pageloom.com/automatic-timezone-detection-with-javascript
From what I understand about this JavaScript code it is very accurate and will be able to return the offset from UST, the corresponding Olson Database timezone name, and handle the daylight savings time issue (ex. -5:00, America/New_york, true).
The only hurdle you will face after getting this code working on your html page will likely be getting these values to asp and then to sql if that is what you need. I achieved this by sending these values as a $.post using JQuery. I think this is the easiest way to do it. I believe the other alternatives are using an AJAX command or cookies.
After I got the values from the JavaScript code to the server I stored them as session variables so they would change if the user on my site logged in from a different timezone then usual. However they could easily be saved to the database as well.
//replace this comment with the most updated timezonedetect code from that first link
var timezone = jstz.determine_timezone();
var tzoffset = timezone.offset();
var tzname = timezone.name();
var tzdst = timezone.dst();
$.post("tzdetect.asp", { tzoffset: tzoffset, tzname: tzname, tzdst: tzdst } );
Then you need to set up the receiving file tzdetect.asp on the server to store the time zone once it's sent.
Working with the time zone once you have it
This article has a good solution to your problem: http://www.codeproject.com/Articles/31146/SQL-2005-Time-Zone-Conversion-Functions
Approach is to set up a scalar function called
NEW_TIME that takes three parameters:
date to convert
original time zone value
conversion time zone
and the function returns the
converted value.
New solution to an old question...
We just had this issue when moving a server from "eastern standard time" to "utc", with all our asp classic apps.
But, we're using SQL server 2017.
And, if you're using SQL server 2016+, you can use the new "at time zone" keyword.
Get your current "offset" from that query:
select datediff(hour, GETUTCDATE() at time zone 'eastern standard time', GETUTCDATE()) as offset
Then, use that offset to handle all your dates in your ASP code, with functions like:
function fromUTC(dt)
fromUTC = dateadd("h", tzOFFSET, dt)
end function
function toUTC(dt)
toUTC = dateadd("h", -1 * tzOFFSET, dt)
end function
function getNow
getNow = fromUTC(now)
end function
You can replace all "now" with "getNow" in your code.
Warning: that this offset is fixed according to the current date. If you need to handle dates from different daylight period, you can use the "at time zone" syntax directly in your SQL query, like:
DECLARE #timezone NVARCHAR(100) = N'eastern standard time'
SELECT
u.name,
u.last_visit at time zone #timezone as last_visit_tz,
u.date_created at time zone #timezone as date_created_tz
FROM users u
You can check e.g. the website http://worldclockapi.com. You can take the current time as timezone.
Example: At http://worldclockapi.com/api/json/est/now.
you can see EST current date, time and other data..
Example: At http://worldclockapi.com/api/json/pst/now you can see PST current date, time and other data...
And you can use XMLHTTP for getting data from external site.
private Function GETHTTP(adres)
Set StrHTTP = Server.CreateObject("Microsoft.XMLHTTP" )
StrHTTP.Open "GET" , adres, false
StrHTTP.sEnd
GETHTTP = StrHTTP.Responsetext
Set StrHTTP = Nothing
End Function
full_data= GETHTTP("http://worldclockapi.com/api/json/est/now")
Afterwards, you use split to to separate by comma:
parts=split(full_data,",")
response.write parts(1)
I think if you choose from below the one you need and then put at the top of your page it will default to that location instead of the server - http://msdn.microsoft.com/en-us/library/ms524330(v=vs.90).aspx
' This file does not need #LCID or #CODEPAGE and
' it does not need to be saved in UTF-8 format because
' there are no literal strings that need formatting or encoding.
Response.Codepage = 65001
Response.Charset = "utf-8"
' See what happens when you uncomment the lines below.
'Response.Codepage = 1252
'Response.Charset = "windows-1252"
ShowDateTimeCurrency 1033, "North America"
ShowDateTimeCurrency 1041, "Japan"
ShowDateTimeCurrency 1049, "Russia"
ShowDateTimeCurrency 1031, "Germany"
ShowDateTimeCurrency 1025, "Saudi Arabia"
ShowDateTimeCurrency 1081, "India"
ShowDateTimeCurrency 2052, "China"
ShowDateTimeCurrency 1042, "Korea"
Sub ShowDateTimeCurrency(iLCID, sLocale)
Response.LCID = iLCID
Response.Write "<B>" & sLocale & "</B><BR>"
Response.Write FormatDateTime(Date, 1) & "<BR>"
Response.Write FormatDateTime(Time, 3) & "<BR>"
Response.Write FormatCurrency(1000) & "<BR>"
Response.Write FormatNumber(50, 3, 0, 0, -1) & " & " & FormatNumber(.02, 3, 0, 0, -1) & "<BR><BR>"
End Sub
Have a look here - http://msdn.microsoft.com/en-us/library/ms524330(v=vs.90).aspx
or another way would be to use date addadd function for time
Please Mark as answer if it helps
thanks