英语和德语的通用日期格式公式



>我在Excel中有一个公式,可以以指定的格式(=text(date,"dd-mm-yyyy")(格式化日期,该文件也用于瑞士语,其系统日期设置为德语(瑞士(。所以它没有正确显示它。如何在公式中做到这一点?

我不想格式化单元格。我需要它在公式中。

=text(date,"dd-mm-yyyy")

该文件将由两个用户(英语和德语(使用。 需要一个科蒙公式。 以及如何在 VBA 中做同样的事情。 我用了

format$(date,"dd-mm-yyyy")

对于英语。

'代码改编自 http://www.vbforums.com/showthread.php?33984-How-to-GET-the-system-date-format-from-regional-settings

选项显式

Private Declare PtrSafe Function GetLocaleInfo Lib "kernel32" Alias "GetLocaleInfoA" (ByVal Locale As Long, ByVal LCType As Long, ByVal lpLCData As String, ByVal cchData As Long) As Long
Private Const LOCALE_USER_DEFAULT = &H400
Private Const LOCALE_SSHORTDATE = &H1F ' short date format string
Private Const LOCALE_SLONGDATE = &H20 ' long date format string
Function LocaleString()
Dim strLocale As String
Dim lngRet As Long
Dim strMsg As String
'Get short date format
strLocale = Space(255)
lngRet = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SSHORTDATE, strLocale, Len(strLocale))
strLocale = Left(strLocale, lngRet - 1)
LocaleString = strLocale
End Function
Function CDateLocale(d As Date) As String
CDateLocale = Format(d, LocaleString())
End Function

在模块中使用它,您可以使用 =CDateLocale(A1( 将 A1 中的日期转换为本地短日期格式,但作为文本而不是日期。

最新更新