Get user specified long date format in UWP - c#

I want to convert a date to the user set long date format. The Current Culture is en-US, but the user is able to set a long date format of his/her choice in Control panel -> Region -> Long Date.
In this case, here I set the Format to Hungarian, and selected the yyyy. MMMM d. format (keeping the Current Culture in en-US).
System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.FullDateTimePattern returns an incorrect pattern.
So does the Windows.​Globalization API.
In my Package.appxmanifest:
<Resources>
<Resource Language="x-generate" />
</Resources>
Anyone knows how to get the date format from control panel -> region -> long date?

Unfortunately, the UWP API's don't expose the Regional Settings; having said that I did find a working solution a while back, though I haven't tested it with Creators Update so can't confirm if it still works!
Update: I've found a non-hacky way of doing this, using the GetLocaleInfoEx Win32 API.

Related

Visual Studio debugger shows Date Time as Ticks when mouse hover instead of an understandable Date String Format

In visual studio (I'm using 2019), during debugging, when I hover over a DateTime object, it shows the date in Ticks instead of a readable date string (such as YYYY-MM-dd HH:mm:ss, etc).
The picture below shows this annoying behavior.
I remember in my old visual studio 2017, it showed date-time objects in "YYYY-MM-DD HH:mm:ss.ttt" format.
How do I change this?
I agree with reynoldsbj. I think you have pinned the Ticks property in the LoadAreaTo Drop down menu bar so that it will overwrite the default Date property.
This is a video about the detailed description:
You should unpin the property Ticks so that it will show date-time objects in YYYY-MM-DD HH:mm:ss.tt format.
Click the dropdown in that previewer and unpin Ticks or pin Date if you want to see both.

How to know when user changed date, time or number formats in Clock and Region system settings in C#?

I need to subscribe to an hypothetical event that should be triggered whenever the user changes date, time, or number formats in Clock and Region settings. Below is the picture of how this settings window look in Windows 10 (I suppose that in older Win versions is pretty much the same stuff):
I have to achieve this in order to call ClearCachedData method on my CurrentCulture.
What I have tried is to subscribe to UserPreferenceChanged event following the solution in this question. Nevertheless the event never fires...
I am using WPF although I believe this should not be relevant, although I mention it in case it is...
Further details
My application has a data grid with numeric value editors (I am using Devexpress's controls although this is may be not relevant), so, suppose I have this cell holding a value of 1.5, this will be like so due to the fact that I have set my numeric formats to an English (US) culture. Now, I go to these settings (while having my app running), and change my numeric formats to German(Germany). Then I want to update the displayed value to 1,5. This feature is already supported on Devexpress's controls and WPF in general, I just need to call ClearCachedData and update my layout.
An already existing application that I know for sure does this is Excel (I am sure there must be a lot more), try yourself to set a float value (1.5 e.g.), and with the window opened go to change your numeric formats with a Germany region: the cell updates its displayed value to 1,6.

Scheduler Calendar datetime Picker time intervals

I need scheduler pop up datetime picker with one hour intervals. I tried this thing after changing outer Html of the popped input screen it will display data in correct way but their are issues in reading the selected data. It read wrong dates after i change the Popup. Please refer the attached images for more info. And want to define time range 8.00 am to 6.00 pmenter image description here
From the provided information it's not clear how exactly you are setting the corresponding option of the DateTimePicker, however the described scenario works as expected on my side - please check the example below:
http://dojo.telerik.com/inonu

How to set ClockIdentifier dynamically in WinRT app

I have a TimePicker and would like to set its ClockIdentifier property dynamically based on the time format supported by the locale of that system. I tried getting the CultureInfo.CurrentUICulture.DateTimeFormat, but, it does not have any property specifying whether current culture set on the system supports 12 hour time format or 24 hours format.
Any ideas?

DateTime is being interpreted as two different formats

I have an MVC application which allows appointment booking. The user can click on a slot in the diary view, which takes them to a page to select the practitioner and confirm.
The query string for this page contains a DateTime which is the time the appointment is to start. This is automatically formatted in US format by Html.ActionLink(...), like so:
/assign?date=04%2F06%2F2011%2009%3A00%3A00
This is correctly deserialised and the view reports that the appointment time will be the 6th of April. It is also stored in a hidden field in the view to be posted to the confirm action; the hidden field has the value: 04/06/2011 09:00:00, rendered by Html.HiddenFor(...). Again, looks like US format.
However, when the form gets posted, the appointment is booked for the 4th of June, presumably interpreting the date as en-GB.
Why would it do that?
That might happen because your server is configured to auto detect the culture of the browser and if the browser preferred culture is en-GB that's what the server will use when binding DateTime parameters:
<globalization culture="auto" uiCulture="auto" />
You could specify it to a fixed culture:
<globalization culture="en-US" uiCulture="en-US" />

Categories

Resources