I'm trying to get the long time format in Windows (like "hh:mm:ss tt"). I can get the short time format like this:
GetLocaleInfoEx(NULL, LOCALE_STIMEFORMAT, format, 100);
I can't seem to find a constant for LOCALE_LTIMEFORMAT or anything like that. I can get the short time, short date and long date, but how can I query the current user's long time format?
As far as I can tell, windows defines the 'long' time format by LOCALE_STIMEFORMAT (set to something like "hh:mm:ss"), and the short time as LOCALE_SSHORTTIME (which, according to MSDN, is valid for Windows 7 and later).
Does that correspond to your findings, i.e. does it match the user preference in the Region and Language Control Panel item?
For the t specifier, if it is not included into the locale format, then either you are left with always using a custom format (like gbjbaanb said), or perhaps examining the format string for the presence of t or tt, and if absent adding it yourself (though, this might lead to odd results for cultures expecting the tt before the general time, for instance). This should not be necessary though, as the time format used by the locale is responsible for yielding time-strings that make sense (distinguishing between AM and PM, for instance).
What you are looking for is already included in LOCALE_STIMEFORMAT. Sample code:
wchar_t format[80]; // 80 is always enough
int ret = GetLocaleInfoEx(
LOCALE_NAME_USER_DEFAULT,
LOCALE_STIMEFORMAT,
format,
sizeof(format) / sizeof(*format));
if (ret == 0) die(GetLastError());
std::wcout << format << std::endl;
Output on my machine (I live in the USA):
h:mm:ss tt
The "tt" part will be absent for any culture or locale customization that does not display the AM/PM designator.
The LOCALE_STIMEFORMAT is the long time format. To get the short time format you can use LOCALE_SSHORTTIME starting with Windows 7 or cut off the seconds.
To confirm this simply change the long time format in your Control Panel / Region and Language settings.
Try using it with the LOCALE_S1159 and LOCALE_2359 constants which return the text for the AM/PM designators.
I think the issue is that time format is a time format, down to the second. You have to format it yourself if you want AM/PM just like you do with daylight savings time or timezone indicators.
Related
I am trying to convert a unix time to datetime depending on its locale given
Example I wanted to get locale Australia and convert UNIX time to date:
<#setting locale= getlocale>
<#assign unix = "1660545165"?number>
<#assign expiryDate = unix.getstarttime()?number?number_to_datetime?string["yyyy-mm-dd"]>
here is the time ${expiryDate}
I searched in google and suggested me to use getstarttime()?number?number_to_datetime?string["yyyy-mm-dd"]
However I am getting an error and currently stuck:
Expected a hash, but this has evaluated to a number
Lot of what's wrong I think is simply unnecessary there. Also based on the format you actually want a date, not a date-time. Here's a working example:
<#assign unixTime = 1660545165>
Here is the time: ${unixTime?number_to_date?string["yyyy-MM-dd"]}
Also usually you want to set the date_format setting to yyyy-MM-dd once (in the Java code, or with <#setting date_format = "yyyy-MM-dd"> near the top of the the template), and then just write ${unixTime?number_to_date} everywhere.
Problem:
In a field called $Detailed Decription$ sometimes dateformat 08/09/2021 is enterd and this need to be converted to swedish format 2022-02-11
I'am going to use BMC Developer studio and make a filter but i cant find a fitting solution for it. Replacing it wont work (i think) becaus it need to have a value to replace it with.
Maby there can be a function that reads regex (\d{2})/(\d{1,2})/(\d{4}) but how can i convert it?
If it's sometimes - look at AR System User Preferencje form. Check certain user's locale and date time config.
Also is important where the data comes from. Could be a browser setting or java script mod.
1- Using Set fields action, copy the date value from Detailed Description to a Date/Time field (i.e. z1D_DateTime01).
2- Using Set fields action and Functions (MONTH, YEAR, DAY, HOUR, MINUTE, SECOND) you can parse the date/time and convert it to format you like.
Something like this:
SwedishDate = YEAR($z1D_DateTime01$) + "-" + MONTH($z1D_DateTime01$) + "-" + DAY($z1D_DateTime01$)
This will capture the parts of date and combine them with "-" in the middle and in the order you want.
I am using GetDateFormatEx (more specifically, ctypes.windll.kernel32.GetDateFormatEx using Python), which is documented at
https://msdn.microsoft.com/en-us/library/windows/desktop/dd318088%28v=vs.85%29.aspx
And using today's date as the SYSTEMTIME input, and a NULL format string and 0 flags. however specifically for the ar-SA locale.
It is returning a value of "06/01/37", which is not what I expected. I expected to be in the ar-SA language (ie, what, in my English eyes, look like squibbles).
I also expected it would return an arabic short date string, specifically, for the gregorian calendar, however it seems to be using the Hijri calendar instead. How do I detect that a Hijri calendar is being used?
So, to re-iterate, what I want to know is:
How do I get the arabic date, something more like: تشرين الأول أكتوبر ١٩ ١٥
How do I detect the type of calendar that the user is expecting to be using?
Is it possible that you yourself has overridden the locale settings for date formatting on your testing PC? Maybe you need to use the LOCALE_NOUSEROVERRIDE flag.
UPDATE
I have tested this in C++
GetDateFormatEx(L"ar-SA", LOCALE_NOUSEROVERRIDE | DATE_AUTOLAYOUT | DATE_LONGDATE, nullptr, nullptr, buf, _countof(buf), nullptr);
The resulting date is
06/محرم/1437
UPDATE 2
This apparently depends on how Windows define the locale. I have tried different combination of the flags (DATE_AUTOLAYOUT | DATE_LONGDATE, DATE_AUTOLAYOUT | DATE_USE_ALT_CALENDAR | DATE_LONGDATE, DATE_AUTOLAYOUT | DATE_USE_ALT_CALENDAR). While for "ar-SA" this gives
06/محرم/1437
06/01/1437
06/01/37
for "ja-JP" (Japanese) it gives
2015年10月19日
平成 27年10月19日
平成 27/10/19
I suspect (not knowing full Windows NLS capabilities), you will have to use either specific formatting string or some other library, like ICU, to get more squigly dates.
UPDATE 3
It probably does not get any more squigly than with DATE_AUTOLAYOUT | DATE_USE_ALT_CALENDAR flags and L"dddd, dd MMMM, yyyy gg" format:
الإثنين, 06 محرم, 1437 بعد الهجرة
UPDATE 4
Further search reveals this:
Note: If you got the Gregorian date with Arabic names, then you probably forgot to set the calendar type to the Hijri calendar.
So it seems your Windows would have to have the Hijri calendar selected in your locale for the numbers to get formatted with the traditional numerals.
UPDATE 5
Finally, how do I detect that the Hijri calendar is being used in that case?
You can detect the calendar that is in use by calling GetLocaleInfoEx() with LOCALE_ICALENDARTYPE as its LCType parameter and comparing the returned number with constants defined in WinNls.h:
#define CAL_HIJRI 6 // Hijri (Arabic Lunar) calendar
#define CAL_UMALQURA 23 // UmAlQura Hijri (Arabic Lunar) calendar
CodeIgniter stores timezones for its date class in
system/language/english/date_lang.php
I would like to change the strings in this file so that
$lang['UM12'] = '(UTC -12:00) Baker/Howland Island';
$lang['UM11'] = '(UTC -11:00) Samoa Time Zone, Niue';
would instead be
$lang['-12:00'] = '(UTC -12:00) Baker/Howland Island';
$lang['-11:00'] = '(UTC -11:00) Samoa Time Zone, Niue';
Is this possible at all?
Any change I make to the UM__ portion of one line makes it show as a blank on the dropdown. The remaining (unchanged) lines appear OK.
I have also tried to clone this file to application/language/english/ with similar bad results.
Any insights on this?
It looks like this would require hacks to the date_helper.php file which I am not willing to do.
Instead, the date class in CI has the timezones() function which allows you to convert from, for example, UM5 to -5. In that case one can wrap this function around the U__ value coming from the view/dropdown -- and then save it to DB as -5 or some other INT.
Since I want to show the user their selected timezone on that same dropdown, I am forced to have DB fields for the U__ and INT timezone formats. As far as I know, there is no CI function to convert from -5 to UM5.
So, for the user, I pull the U__ format into the view to autopopulate the dropdown.
For timezone conversions and such, I use the INT format.
In Ruby, how do I convert theFixnum 1291132740128 (milliseconds since the epoch) to the equivalent HTML5 global time & date string (Also see HTML5 time element explanation. E.g., 1979-10-14T12:00:00.001-04:00)?
My first attempt is:
> Time.at(1291132740128/1000.0).strftime("%Y-%m-%dT%H:%M:%S-%Z")
=> "2010-11-30T10:59:00-EST"
But, (1) how do I get the milliseconds? Does Time store the milliseconds?
And, (2) how do I get the timezone to be -0400 or -0500, depending on whether it's daylight savings time?
EDIT: Now that I think about it, perhaps it's better to keep it as 1291132740128 and do the conversion with JavaScript according to the browser location. What do you think?
1) %3N in strftime will give you milliseconds:
Time.at(1291132740128/1000.0).strftime("%Y-%m-%dT%H:%M:%S.%3N-%Z")
=> "2010-11-30T16:59:00.128-CET"
2) Isn't that automatic?
EDIT: What would happen if the user had his JS turned off in that case? I think it depends on the usage.
It doesn't show the miliseconds but you could try this:
Time.at(1291132740128/1000.0).xmlschema
=> "2010-11-30T16:59:00+01:00"