如何以Lotusscript格式(现在为"dd/mmm/yyyy")指定月份的语言(CultureInfo) [英] how to specify month's language (CultureInfo) in Lotusscript Format (now, "dd/mmm/yyyy")
问题描述
这个问题是LOTUSCRIPT版本的 datetime.to月和日语言
This question is the LOTUSCRIPT version of datetime.tostring month and day language
需要描述: 我需要使用dd/mmm/yyyy格式的字符串日期(例如:"2014年2月28日").我不需要这3个字母的英语(intl)语言,并且不在LOCAL客户端中使用的默认区域设置.
Need description: I need a string date in the dd/mmm/yyyy format (ex: "28 feb 2014"). I don't want english (intl) language for this 3 letters, and not the default regional setting in use in the LOCAL client.
约束:
- 使用的编程语言:Lotus Notes客户端的Lotusscript.
- 我无法更改客户端计算机的区域设置.几乎不能接受特定于Lotus Notes的注册表很麻烦(例如:我猜format $不能解决我的问题.我可以使用什么?我最后的选择是选择案例月份(现在)案例1:resu = resu +"jan" ....
I guess format$ will not solve my problem. What can I use ? My last resort will be select case month(now) case 1: resu = resu + " jan " ....
有更好的主意吗?预先感谢您提出这样的似曾相识"主题.
Any better idea ? Thanks in advance for a such "deja vu" topic.
推荐答案
如果使用Windows,则可以使用WinApi
SYSTEMTIME
结构.另外,您还需要使用Day, Month, Year, and Era Format Pictures
主题,用于设置日期和时间的语言和格式.
这是示例:If you are using Windows you can use WinApi
GetDateFormat
function. For this function you need to createSYSTEMTIME
structure. Also you need to useLanguage Identifier Constants and Strings
andDay, Month, Year, and Era Format Pictures
topics for setting language and format of date and time.
Here is example:'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
类来设置语言和日期.
这是示例:
Another way is to use LS2J. For this you can useSimpleDateFormat
class and itsformat
method. Also you need to useLocale
class andCalendar
class for setting language and date.
Here is example:'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")
在此示例中,我使用了此处获取语言代码,并从此处.
对于SimpleDateFormat
对象,我使用了In this example I have used this constructor for getting
Locale
object. You can get language codes from here and country codes from here.
ForSimpleDateFormat
object I have used this constructor.这篇关于如何以Lotusscript格式(现在为"dd/mmm/yyyy")指定月份的语言(CultureInfo)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!