获得保证具有完整(4 位)年份编号的 LOCALE

编程入门 行业动态 更新时间:2024-10-23 17:35:14
本文介绍了获得保证具有完整(4 位)年份编号的 LOCALE_SSHORTDATE 的正确方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我想创建一个显示日期和时间的日期时间选择器控件,作为 DTS_SHORTDATECENTURYFORMATDTS_TIMEFORMAT 样式的组合.由于日期时间选择器中没有内置这种样式,因此我必须自己使用 GetLocaleInfoEx() 来完成.

I want to create a date-time picker control that shows both date and time, as a combination of the DTS_SHORTDATECENTURYFORMAT and DTS_TIMEFORMAT styles. Since there is no such style built into the date-time picker, I have to do it myself with GetLocaleInfoEx().

我注意到默认情况下,GetLocaleInfoEx(LOCALE_SSHORTDATE) 似乎返回一个四位数的年份,这正是我想要的.这可靠吗?它没有记录在任何地方,只是 LOCALE_SSHORTDATE 可以有多个字符串.如果我必须枚举可能的字符串,我怎么知道哪个是我想要的?我是否只查找包含 yyyy 的第一个字符串?这对我来说听起来不可靠,至少它本身不可靠......

I notice that by default, GetLocaleInfoEx(LOCALE_SSHORTDATE) seems to return a four-digit year, which is what I want. Is this reliable? It's not documented anywhere, only that there can be more than one string for LOCALE_SSHORTDATE. If I have to enumerate the possible strings, how would I know which one is the one I want? Do I just look for the first string to contain yyyy? That doesn't sound reliable to me, at least not on its own...

谢谢.

推荐答案

不,您不能依赖 LOCALE_SSHORTDATE 有四位数的年份,因为用户可以通过 Region 进行配置提供控制面板和两位数年份选项.

No you can't rely on LOCALE_SSHORTDATE having a four-digit year, since the user is able to configure this through the Region control panel and options with two-digit years are available.

如果您想强制使用四位数年份(并覆盖用户的首选项),您也可以提供您自己的短日期字符串.或者,您可以扫描用户的字符串并将yy"更改为yyyy".

If you want to enforce a four digit year (and override the user's preference) you may as well just provide your own short date string. Alternatively, you could scan the user's string and change "yy" to "yyyy".

这篇关于获得保证具有完整(4 位)年份编号的 LOCALE_SSHORTDATE 的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-26 01:04:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1126849.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:年份   编号   完整   LOCALE

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!