不管区域设置如何,都将日期强制为美国格式 [英] Force date to US format regardless of locale settings

查看:87
本文介绍了不管区域设置如何,都将日期强制为美国格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一行VB6程序:

strDate = Format(Date, "ddmmmyyyy")

我需要它始终根据Windows(英语)(美国)的文化"设置以这种格式显示:

I need it to always come out in this format according to the Cultural settings for Windows for English (United States):

17Jul2012

不幸的是,当将文化设置为其他语言(例如法语)时,我得到了:

Unfortunately when the culture is set to something else, French, for example, I get this:

17juil2012

有什么方法可以使日期格式始终使用美国英语格式?

Is there any way to make the date format always use the English US formatting?

推荐答案

为什么要将月份名称硬编码为一个简单的函数,而不是仅仅尝试强制使用一种特定于文化的格式,

Rather than mess about trying to enforce a culture-specific format, why not just hard code the month names into a simple function like this:

Private Function GetEnglishDate(ByVal d As Date) As String
    Dim monthNames
    monthNames = Array("", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")
    GetEnglishDate = Day(d) & monthNames(Month(d)) & Year(d)
End Function

用法:

strDate = GetEnglishDate(myDate)

这篇关于不管区域设置如何,都将日期强制为美国格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆