Windows を使用している場合は、WinApiGetDateFormat
関数を使用できます。この関数では、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")
この例では、オブジェクトを取得するためにこのコンストラクターを使用しました。Locale
言語コードはこちらから、国コードはこちらから取得できます。オブジェクトには、このコンストラクターを使用
しました。SimpleDateFormat