I set a winforms combobox with the time zones DisplayName:
var zoneList = TimeZoneInfo
.GetSystemTimeZones()
.Where(z => z.BaseUtcOffset.Minutes == 0)
.Select(z => z.DisplayName);
It shows a list like this:
...
(UTC-01:00) Azores
(UTC-01:00) Cabo Verde Is.
(UTC) Casablanca
(UTC) Co-ordinated Universal Time
(UTC) Dublin, Edinburgh, Lisbon, London
(UTC) Monrovia, Reykjavik
(UTC+01:00) Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna
...
I want to sent the default item to (UTC) Co-ordinated Universal Time. However, TimeZoneInfo.Utc.DisplayName returns UTC. It is unusual because the upper enumeration shows different DisplayName.
TimeZoneInfo.FindSystemTimeZoneById("UTC") also returns "UTC".
TimeZoneInfo.FindSystemTimeZoneById("(UTC) Co-ordinated Universal Time") and TimeZoneInfo.FindSystemTimeZoneById("Co-ordinated Universal Time") do not work.
How to get the localized string that corresponds to shown in the enumeration (UTC) Co-ordinated Universal Time?
The only solution I can figure out is to store the string "(UTC) Co-ordinated Universal Time", but I'm afraid the upper list may change in different localization.
A few things:
The DisplayName is not the ID. Only the values returned by the Id property are suitable for use with the FindSystemTimeZoneById method.
For your dropdown list, you should show the DisplayName, but you should store only the Id.
The DisplayName, StandardName and DaylightName properties are localized by the operating system, not by the globalization features of the .NET Framework.
The IDs will always be in English. They will never change for localization.
You should never show the IDs to the end-user or interpret them in any particular way. There are many different conflicting conventions used, and some that are just made up. See the section on Windows time zones in the timezone tag wiki for some examples.
"Coordinated" is a single non-hyphenated word. These are correct in Windows, so I think you must have added the hyphen yourself.
Recognize that the offsets shown in the display names are just the base offsets. They do not indicate whether or not the time zone adjusts for daylight saving time or not. Nor do the offsets in this list change when daylight saving time is in effect.
You are correct that TimeZoneInfo.Utc.DisplayName == "UTC", and so does TimeZoneInfo.FindSystemTimeZoneById("UTC").DisplayName. However, the UTC entry returned by TimeZoneInfo.GetSystemTimeZones() has the full form of the display name: "(UTC) Coordinated Universal Time". Therefore, if you're displaying a dropdown list by enumerating the results from TimeZoneInfo.GetSystemTimeZones(), then you can just use the results as-is.
But if you want to get that display name directly, you will either have to do this:
string s = TimeZoneInfo.GetSystemTimeZones().First(x => x.Id == "UTC").DisplayName;
Or, this:
string key = #"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones\UTC";
string s = Registry.GetValue(key, "Display", null) as string;
Again, remember that all localization of time zone display names is done by the operating system. Therefore, this approach works fine for Windows desktop applications, but doesn't make a whole lot of sense for web apps. Also, if your application supports multiple languages internally, you won't be able to rely on .NET Globalization for any time zone display names. In that scenario, you will need to provide your own source of display names, perhaps in a .resx file, or you can look into using my TimeZoneNames library.
Hmm, I found the answer by printing the time zone's Id.
The desired string is printed with:
TimeZoneInfo.FindSystemTimeZoneById("GMT Standard Time"); // Wrong
Edit:
As Matt Johnson noted, the above code shows the London time zone.
Here is another try:
TimeZoneInfo.GetSystemTimeZones().First(t=>t.Id=="UTC").DisplayName
Related
I created Data element ZDT_NKS_DESCR and flagged Change Document when creating for logging the changes on WebUI table. Everything is good, but the time of changing logging wrong. It adds +3 hours to current time.
For example: if the current time is 10:00 it's logging 13:00 on Web UI.
How can I fix it? Can anybody explain what happens?
Here is my data element (NB: in fact I ticked the "Change Document" checkbox later on):
Here is the change logging on Web UI table, the time should be 9:48, 9:48, 9:45 :
P.S: On Web UI timezone is correct.
In ABAP-based softwares, many screens display the dates using the SAP system time unfortunately (that's been always a big problem). Some modules sometimes display the local time (according to user's time) or according to the local time of the partner (transportation modules for instance). So users have to learn for every module or every screen what kind of date/time it is.
Even in database tables, it's impossible to be sure what kind of date/time it is. Usually it's the system time. But some modules may store the date/time according to UTC.
I guess that the times of the change documents are displayed in the system time.
The system time can be seen via the classic SAP GUI, in the menu System > Status > System time.
Here's my final solution based on Sandra answer:
In xxxxx_WRITE_DOCUMENT FM we should change time_of_change value from utime to sy-uzeit. Your CHANGEDOCUMENT_CLOSE function should look like this:
CALL FUNCTION 'CHANGEDOCUMENT_CLOSE'
EXPORTING
objectclass = 'ZCHD00005'
objectid = objectid
date_of_change = udate
time_of_change = sy-uzeit (it's current system time)
tcode = tcode
username = username
object_change_indicator = object_change_indicator
no_change_pointers = no_change_pointers
EXCEPTIONS
header_insert_failed = 1
object_invalid = 2
open_missing = 3
no_position_inserted = 4
OTHERS = 5.
If it's necessary, you should change the timezone on WebUI. I'm using system timezone, because of this on WebUI->Personalization->Timezone I choose UTC from F4.
Save and activate your solution!
I'm a DNN beginner. I am currently building a module in which I can display statistics. My DotNetNuke Version is 7.0. The statistic is from Chartjs. For this statistic I would like to implement filters. These filters should be datepickers. As UI element I have now included a textbox with TextMode='Date'. But currently I have problems to set the default value of this field. The default value should be 01.01. of the current year.
I have already tried to set the value via C# server side. Unfortunately without success. I also tried to set the value on the client side via JavaScript. Unfortunately also without success.
These are some lines I tried in JavaScript:
document.getElementById(<%= this.DatumVon.AccessKey %>).value = "01.01.2019";
document.getElementById(<%= this.DatumVon.AccessKey %>).innerText = "01.01.2019";
document.getElementById("DatumVon").value = "01.01.2019";
These are some lines I tried in C# in the method "Page_Load" (server side):
this.DatumVon.Text = "01.01.2019";
I expected the value of the TextBox to be 01.01.2019. However, it currently only contains dd.mmm.yyyy. How can I change this?
Thank you.
There is something wrong with your localization. Please refer to the jQuery UI datepicker documentation (the "Localization" section), this should give you the answer.
wow... I solved it. I made it. Sometimes the solution is right in front of you and you don't see it. Michael Tobisch was absolutely right. When setting the value, the format is very important. I have always used the German format. A DNN TextBox with TextMode="Date" can't handle that. DNN converts this TextBox into an HTML input field. But this input field can only be clear with the format "yyyy-mm-dd". Depending on the geographical position of the client (at least that's what I think) the text displayed in the input field will be formatted. But the value of the input field always has the same format ("yyyy-mm-dd"). So very important here: the displayed text and the actual value have different formats.
Many thanks again to Michael Tobisch for the mental inspiration and the patience with me.
What is also important is that the access to the actual ID of a DNN element works as follows: this.Element.ClientID and not as I assumed before this.Element.AccessKey. This was also buggy.
I have an MVC 4 application with international users (all over the world). I want to add a new page called profile settings where users can select their regional settings and by that I mean that they should be able to select:
- time zone (UTC +- .....)
- date format (dd.MM.yyyy or dd/MM/yyyy or MM/dd/yyyy ....)
- time format (12/24 - AM PM)
- number format (1234.56 or 1234,56)
After the user selects his regional settings, all specific data (date, time, number ...) should be shown in that specific format.
Any advice how to make this work?
Most of the time, you shouldn't expose each and every detail of the culture format to your users. Instead, provide a drop-down list of cultures you want to support. Cultures are specified using codes. Some common codes are en-US (English/USA), es-MX (Spanish/Mexico) and de-DE (Germany/German). The first part refers to the language, and the second part refers to the specific country or region.
Once you have the selected culture code, you can apply it to each user, such as:
CultureInfo culture = new CultureInfo("en-US");
Thread.CurrentThread.CurrentCulture = culture;
If you are using culture-specific resource files, then you will also need:
Thread.CurrentThread.CurrentUICulture = culture;
There are several places you could do this, but a common location is in the Application_BeginRequest event in your global.asax file.
There is a good tutorial on MSDN here.
While it is common to think about time zones when you are considering regional settings, they are actually quite different things and should be considered separately. Time zones can't really be set globally, you need to consider how they affect your application logic in each and every place you work with date and time. You should look into the TimeZoneInfo class. If you have questions, please ask separately. Although if you search, you may find that many have already been answered.
Here is the problem.
I have to create a submission form on my Yii-based website. The form requires to enter a datetime range.For that I am using "jui datetimepicker" third-party Yii extension.
http://www.yiiframework.com/extension/datetimepicker/
I use two date fields with this extension pertaining to start and end time respectively. So, what I want to achieve is be able to restrict the start datetime only to time in the future (neither past dates nor time should be selected) and the end time itself should be restricted to the maximum of three hours following the start time.
EXAMPLE: a user wants to schedule an event. They choose a date and time, which are of course in the future. Let's say they choose March 15, 13 O'clock as the start time in the start time field. Once they are done and move to the next field ("end time"), the respective datetimepicker restricts the range of time from March 15, 13:00 to March 15, 16:00.
Hence the second datetimepicker should be dynamically updated depending on the input of the first one.
It's possible o specify date range in the datetimepicker starting from the current date, but there is nothing like that for the time selection, so a user still can select time which has already passed.
It's not that I want to solve this problem with this extention, if anybody has any suggestions about YII solutions allowing to specify a datetime range in the most clean and effective way - it would be much appreciated.
You should use the edaterangepicker extension instead.
Given the API for the jquery timepicker addon. you should add the following to your widget call (along side 'model','attribute', etc)
'options'=>array(
'minDateTime'=>'<start dateTime here>',
'onSelect'=>'<JS function to run>'
)
The function you run on the "onSelect" event should dynamically set the minDateTime for the second dateTime input field, for ex:
function (selectedDateTime){
<EndDatePickerElement>.datetimepicker('option', 'minDateTime', <start dateTime here using selectedDateTime> );
}
There are more examples on the link provided earlier if you need to make it even more precise (like say if you wanted the starting date to be pushed back by the amount of time the user was on the page rather than it being set when the page was loaded. etc...)
I want Rails (3.2) to use the American date format 03/14/2012 unless I say otherwise.
I have the I18n gem installed, downloaded (and modified) the config/locales/en-US.yml file to have the default format as default: ! '%m/%d/%Y', set my application.rb default locale as config.i18n.default_locale = "en-US", and restarted.
When dates are displayed (e.g. a simple view) they still have the format 2012-03-14. If I use the I18n.l method, the date displays as desired, 03/14/2012. So localization is working through the I18n class.
I guess I was expecting the meaning of "default" to be, "this is the one to use if you're not otherwise told to localize or translate." Apparently I expected wrong :-)
So further digging revealed I could change the defaults for date and time in an initializer, such as config/initializers/date_formats.rb, e.g.
Date::DATE_FORMATS[:default]="%m/%d/%Y"
Time::DATE_FORMATS[:default]="%m/%d/%Y %H:%M"
This appears to do what I want. Several alarming posts suggests that this will screw up how dates are stored in the database, but my tests (using PostgreSQL) suggest that this is not a problem.
So (rant) why the heck shouldn't all apps observe the default locale without wrapping every date on the face of the earth with l and t helpers?
And (actual question) will I cause permanent harm to myself or others by changing the default date and time formats for my application in an initializer?
I had the same problem and this gem helped me https://github.com/jeremyevans/ruby-american_date
Just add it to your Gemfile, no settings needed