这个问题是LOTUSCRIPT版本的 datetime.tostring month and day language
需要说明: 我需要一个dd / mmm / yyyy格式的字符串日期(例如:“2014年2月28日”)。我不希望这3个字母使用英语(国际语言)语言,而不是LOCAL客户端中使用的默认区域设置。
约束:
我猜格式$不会解决我的问题。我可以用什么?我的最后一招将是选择案例月(现在)案例1:resu = resu +“jan”....
有什么好主意吗?提前感谢这个“似曾相识”的主题。
[编辑我之前写的“我不会英语”应该是“我不想要”。 LS ALWAYS中的格式返回英文]
答案 0 :(得分:2)
如果您使用的是Windows,则可以使用WinApi GetDateFormat
功能。对于此功能,您需要创建SYSTEMTIME
结构。您还需要使用Language Identifier Constants and Strings
和Day, 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
方法。您还需要使用Locale
课程和Calendar
课程来设置语言和日期
这是一个例子:
'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")
在此示例中,我使用this constructor 来获取Locale
对象。您可以从here获取语言代码,从here获取国家/地区代码
对于SimpleDateFormat
对象,我使用了this构造函数。
答案 1 :(得分:1)
我相信Format(Now, "dd mmm yyyy")
会用英语生成这个月,但我不是100%肯定。
如果没有,您可以使用
Day(Now) & " " & Mid("JanFebMarAprMayJulJunAugSepOctNovDec", 3* Month(Now) -2, 3) & " " & Year(Now)
答案 2 :(得分: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