0

这个问题是 LOTUSCRIPT 版本的 datetime.tostring 月份和日期语言

需要说明:我需要 dd/mmm/yyyy 格式的字符串日期(例如:“2014 年 2 月 28 日”)。我不想要这 3 个字母的英语(国际)语言,而不是LOCAL 客户端中使用的默认区域设置。

约束

  1. 使用的编程语言:Lotus Notes 客户端的 Lotusscript。
  2. 我无法更改客户端计算机的区域设置。几乎不能接受特定于 Lotus Notes注册表是痛苦的(如:http ://searchdomino.techtarget.com/tip/Resolve-Domino-date-format-problems-for-dd-mm-yyyy-format )

我猜 format$ 不会解决我的问题。我可以用什么?我最后的手段是选择案例月份(现在)案例1:resu = resu +“jan” ....

有更好的主意吗?在此先感谢您提供这样一个“似曾相识”的话题。

[编辑我以前写过“我不想英语”,而应该是“我想要”。LS 中的格式总是返回英文]

4

3 回答 3

2

我相信这Format(Now, "dd mmm yyyy")会产生英语月份,但我不是 100% 确定。

如果没有,您可以使用

Day(Now) & " " & Mid("JanFebMarAprMayJulJunAugSepOctNovDec", 3* Month(Now) -2, 3) & " " & Year(Now)

于 2014-06-12T13:29:41.563 回答
2

如果您使用的是 Windows,则可以使用 WinApiGetDateFormat函数。对于此功能,您需要创建SYSTEMTIME结构。您还需要使用Language Identifier Constants and StringsDay, Month, Year, and Era Format Pictures主题来设置日期和时间的语言和格式。
这是示例:

'Declarations
Type SYSTEMTIME
    wYear As Integer
    wMonth As Integer
    wDayOfWeek As Integer
    wDay As Integer
    wHour As Integer
    wMinute As Integer
    wSecond As Integer
    wMilliseconds As Integer
End Type

Declare Function GetDateFormat Lib "kernel32" Alias "GetDateFormatA" (_
Byval Locale As Long,_
Byval dwFlags As Long,_
lpDate As SYSTEMTIME,_
Byval lpFormat As String,_
Byval lpDateStr As String,_
Byval cchDate As Long) As Long

Function FormatDate(value As Variant, locale As Long, formatString As String) As String

    Dim buffer As String, systemTime As SYSTEMTIME

    systemTime.wYear = Year(value)
    systemTime.wMonth = Month(value)
    systemTime.wDay = Day(value)

    buffer = String(255, 0)

    GetDateFormat locale&, 0, systemTime, formatString$ , buffer, Len(buffer)

    FormatDate$ = Left$(buffer, Instr(1, buffer, Chr$(0)) - 1)

End Function

'Usage
MessageBox FormatDate(Now, &h40c, "dd MMM yyyy")
'&h40c - is fr-FR locale (0x040c)


另一种方法是使用 LS2J。为此,您可以使用SimpleDateFormat类及其format方法。您还需要使用Localeclass 和Calendarclass 来设置语言和日期。
这是示例:

'Declarations
Uselsx "*javacon"'Include this for using Java objects in LotusScript

Function FormatDate(value As Variant, language As String, country As String, formatString As String) As String

    Dim javaSession As New JavaSession

    Dim localeClass As JavaClass
    Dim locale As JavaObject

    Dim calendarClass As JavaClass
    Dim calendar As JavaObject

    Dim dateFormatClass As JavaClass
    Dim dateFormat As JavaObject

    Set localeClass = javaSession.GetClass("java/util/Locale")
    Set locale = localeClass.CreateObject("(Ljava/lang/String;Ljava/lang/String;)V", language$, country$)

    Set calendarClass = javaSession.GetClass("java/util/Calendar")
    Set calendar = calendarClass.GetMethod("getInstance", "()Ljava/util/Calendar;").Invoke()
    'You need to subtract 1 from month value
    Call calendar.set(Year(value), Month(value) - 1, Day(value))

    Set dateFormatClass = javaSession.GetClass("java/text/SimpleDateFormat")
    Set dateFormat = dateFormatClass.CreateObject("(Ljava/lang/String;Ljava/util/Locale;)V", formatString$, locale)

    FormatDate$ = dateFormat.format(calendar.getTime())

End Function

'Usage
MessageBox FormatDate(Now, "fr", "FR", "dd MMM yyyy")

在这个例子中,我使用了这个构造函数来获取Locale对象。您可以从这里获取语言代码和从这里获取国家代码。 对于对象,我使用了这个构造函数。
SimpleDateFormat

于 2014-06-13T08:13:41.557 回答
1

我没有看到比在您自己的函数中手动构造日期字符串更好的方法:

Function FormatDate(sourceDate as Variant) As String

    Dim months[1 to 12] as String
    months[1] = "Jan"
    months[2] = "Feb"
    months[3] = "Mar"
    months[4] = "Apr"
    months[5] = "May"
    months[6] = "Jun"
    months[7] = "Jul"
    months[8] = "Aug"
    months[9] = "Sep"
    months[10] = "Oct"
    months[11] = "Nov"
    months[12] = "Dec"

    Dim monthPart as String
    Dim dayPart as String
    Dim yearPart as String

    dayPart = Format(sourceDate, "dd")
    yearPart = Format(sourceDate, "yyyy")
    monthPart = months[Month(sourceDate)]

    FormatDate = dayPart & " " & monthPart & " " & yearPart

End Function
于 2014-06-12T13:45:21.533 回答