java对时间和日期的处理_处理日期和时间

java对时间和日期的处理

这些是一些如何格式化日期和时间数据的示例。

随附的文档和其他示例说明了如何使用日期和时间数据。

Option Explicit 
Private Sub Form_Load()
Dim MYDATE As Date
Dim MYTIME As Date
Dim MYDATETIME As Date
Dim TEXTSTRING As String
   With Me
      .Caption = "Working with date and time_5. Formating"
      .AutoRedraw = True
      .Height = 13000
      .Width = 10000
      .Top = 0
      .Left = 0
   End With
   MYDATE = "9/6/2004" '§ weekday= thursday
   MYTIME = "2:6:9"
   MYDATETIME = "9/6/2004 2:6:9" '§ weekday= thursday
   Print "Format Function"
'§ User-Defined Date/Time Formats
   Print "User-Defined Date/Time Formats"
'§ DATE
   Print "== Date =="
   Print "Format(MYDATE, "; """"; "dd/mm/yy"; """"; ") !! Date separator !! ==>"; _
        Tab(80); Format(MYDATE, "dd/mm/yy")
   Print "Format(MYDATETIME, "; """"; "dd-mm-yy"; """"; ") !! other characters may be used !! ==>"; _
        Tab(80); Format(MYDATETIME, "dd-mm-yy")
   Print "Format(MYDATE, "; """"; "d"; """"; ") !! number without a leading zero !! ==>"; _
        Tab(80); Format(MYDATE, "d")
   Print "Format(MYDATE, "; """"; "dd"; """"; ") !! number with a leading zero !! ==>"; _
         Tab(80); Format(MYDATE, "dd")
   Print "Format(MYDATE, "; """"; "ddd"; """"; ") !! abbreviation !! ==>"; _
         Tab(80); Format(MYDATE, "ddd")
   Print "Format(MYDATE, "; """"; "dddd"; """"; ") !! full name !! ==>"; _
         Tab(80); Format(MYDATE, "dddd")
   Print "Format(MYDATE, "; """"; "ddddd"; """"; ") !! complete date !! ==>"; _
         Tab(80); Format(MYDATE, "ddddd")
   Print "Format(MYDATE, "; """"; "dddddd"; """"; ") !! serial number as a complete date !! ==>"; _
         Tab(80); Format(MYDATE, "dddddd")
   Print "Format(MYDATE, "; """"; "w"; """"; ") !! day of the week as a number (first day of week: Sunday) !! ==>"; _
         Tab(100); Format(MYDATE, "w")
   Print "Format(MYDATE, "; """"; "w"; """"; ", vbThursday) !! day of the week as a number (first day of week: Thursday) !! ==>"; _
         Tab(100); Format(MYDATE, "w", vbThursday)
   Print "Format(MYDATE, "; """"; "ww"; """"; ") !! week of the year as a number (first week: with 1 Jan) !! ==>"; _
         Tab(100); Format(MYDATE, "ww")
   Print "Format(MYDATE, "; """"; "ww"; """"; ", , vbFirstFullWeek) !! first week: first full week !! ==>"; _
         Tab(100); Format(MYDATE, "ww", , vbFirstFullWeek)
   Print "Format(MYDATE, "; """"; "m"; """"; ") !! month as a number without a leading zero !! ==>"; _
         Tab(80); Format(MYDATE, "m")
   Print "Format(MYDATE, "; """"; "mm"; """"; ") !! month as a number with a leading zero !! ==>"; _
         Tab(80); Format(MYDATE, "mm")
   Print "Format(MYDATE, "; """"; "mmm"; """"; ") !! month as an abbreviation !! ==>"; _
         Tab(80); Format(MYDATE, "mmm")
   Print "Format(MYDATE, "; """"; "mmmm"; """"; ") !! month as a full month name !! ==>"; _
         Tab(80); Format(MYDATE, "mmmm")
   Print "Format(MYDATE, "; """"; "q"; """"; ") !! quarter of the year as a number !! ==>"; _
         Tab(80); Format(MYDATE, "q")
   Print "Format(MYDATE, "; """"; "y"; """"; ") !! day of the year as a number !! ==>"; _
         Tab(80); Format(MYDATE, "y")
   Print "Format(MYDATE, "; """"; "yy"; """"; ") !! year as a 2-digit numbe  !! ==>"; _
         Tab(80); Format(MYDATE, "yy")
   Print "Format(MYDATE, "; """"; "yyyy"; """"; ") !! year as a 4-digit number !! ==>"; _
         Tab(80); Format(MYDATE, "yyyy")
'§ Time
   Print "== Time =="
   Print "Format(MYTIME, "; """"; "hh-nn-ss"; """"; ") !! Time separator !! ==>"; _
        Tab(80); Format(MYTIME, "hh-nn-ss")
   Print "Format(MYDATETIME, "; """"; "hh.nn.ss"; """"; ") !! Time separator !! ==>"; _
        Tab(80); Format(MYDATETIME, "hh.nn.ss")
   Print "Format(MYTIME, "; """"; "h"; """"; ") !! hour as a number without leading zeros !! ==>"; _
        Tab(80); Format(MYTIME, "h")
   Print "Format(MYTIME, "; """"; "hh"; """"; ") !! hour as a number with leading zeros !! ==>"; _
        Tab(80); Format(MYTIME, "hh")
   Print "Format(MYTIME, "; """"; "n"; """"; ") !! minute as a number without leading zeros !! ==>"; _
        Tab(80); Format(MYTIME, "n")
   Print "Format(MYTIME, "; """"; "nn"; """"; ") !! minute as a number with leading zeros !! ==>"; _
        Tab(80); Format(MYTIME, "nn")
   Print "Format(MYTIME, "; """"; "s"; """"; ") !! second as a number without leading zeros !! ==>"; _
        Tab(80); Format(MYTIME, "s")
   Print "Format(MYTIME, "; """"; "ss"; """"; ") !! second as a number with leading zeros !! ==>"; _
        Tab(80); Format(MYTIME, "ss")
   Print "Format(MYTIME, "; """"; "ttttt"; """"; ") !! complete time !! ==>"; _
        Tab(80); Format(MYTIME, "ttttt")
   Print "Format(MYTIME, "; """"; "h.n.s AM/PM"; """"; ") !! 12-hour clock and 'AM' before noon; 'PM' between noon and 11:59 P.M !! ==>"; _
        Tab(110); Format(MYTIME, "h.n.s AM/PM")
   Print "Format(MYTIME, "; """"; "h.n.s am/pm"; """"; ") !! 12-hour clock and 'am' before noon; 'pm' between noon and 11:59 P.M !! ==>"; _
        Tab(110); Format(MYTIME, "h.n.s am/pm")
   Print "Format(MYTIME, "; """"; "h.n.s A/P"; """"; ") !! 12-hour clock and 'A' before noon; 'P' between noon and 11:59 P.M !! ==>"; _
        Tab(110); Format(MYTIME, "h.n.s A/P")
   Print "Format(MYTIME, "; """"; "h.n.s a/p"; """"; ") !! 12-hour clock and 'a' before noon; 'p' between noon and 11:59 P.M !! ==>"; _
        Tab(110); Format(MYTIME, "h.n.s a/p")
   Print "Format(MYTIME, "; """"; "h.n.s AMPM"; """"; ") !! 12-hour clock, AM and PM string literal as defined by your system !! ==>"; _
        Tab(110); Format(MYTIME, "h.n.s AMPM")
'§ Date and Time
   Print "== Date and Time =="
   Print "Format(MYDATETIME, "; """"; "c"; """"; ") !! date as ddddd and the time as ttttt !! ==>"; _
        Tab(80); Format(MYDATETIME, "c")
   Print "Format(MYDATETIME, "; """"; "dd-mm-yy h.n.s AM/PM"; """"; ") !! mix !! ==>"; _
        Tab(80); Format(MYDATETIME, "dd-mm-yy h.n.s AM/PM")
   Print "============================================"
'§ Predefined date and time format names
   Print "Predefined date and time format names"
'§ DATE
   Print "== Date =="
   Print "Format(MYDATETIME, "; """"; "General Date"; """"; ") !! is determined by your system settings !! ==>"; _
        Tab(110); Format(MYDATETIME, "General Date")
   Print "Format(MYDATETIME, "; """"; "Long Date"; """"; ") !! according to your system's long date format !! ==>"; _
        Tab(110); Format(MYDATETIME, "Long Date")
   Print "Format(MYDATETIME, "; """"; "Medium Date"; """"; ") !! appropriate for the language version of the host application !! ==>"; _
        Tab(110); Format(MYDATETIME, "Medium Date")
   Print "Format(MYDATETIME, "; """"; "Short Date"; """"; ") !! using system's short date format !! ==>"; _
        Tab(110); Format(MYDATETIME, "Short Date")
'§ Time
   Print "== Time =="
   Print "Format(MYDATETIME, "; """"; "Long Time"; """"; ") !! system's long time format !! ==>"; _
        Tab(110); Format(MYDATETIME, "Long Time")
   Print "Format(MYDATETIME, "; """"; "Medium Time"; """"; ") !! in 12-hour format using hours and minutes and the system AM/PM  !! ==>"; _
        Tab(110); Format(MYDATETIME, "Medium Time")
   Print "Format(MYDATETIME, "; """"; "Short Time"; """"; ") !! 24-hour format !! ==>"; _
        Tab(110); Format(MYDATETIME, "Short Time")
   Print "##########################################################"
   Print "FormatDateTime Function"
'§ User-Defined Date/Time Formats
   Print "User-Defined Date/Time Formats"
'§ DATE
   Print "== Date =="
   Print "FormatDateTime(MYDATETIME, vbGeneralDate) !! is determined by your system settings !! ==>"; _
        Tab(110); FormatDateTime(MYDATETIME, vbGeneralDate)
   Print "FormatDateTime(MYDATETIME, vbLongDate) !! according to your system's long date format !! ==>"; _
        Tab(110); FormatDateTime(MYDATETIME, vbLongDate)
   Print "FormatDateTime(MYDATETIME, vbShortDate) !! using system's short date format !! ==>"; _
        Tab(110); FormatDateTime(MYDATETIME, vbShortDate)
'§ Time
   Print "== Time =="
   Print "FormatDateTime(MYDATETIME, vbLongTime) !! system's long time format !! ==>"; _
        Tab(110); FormatDateTime(MYDATETIME, vbLongTime)
   Print "FormatDateTime(MYDATETIME, vbShortTime) !! 24-hour format !! ==>"; _
        Tab(110); FormatDateTime(MYDATETIME, vbShortTime)
End Sub
附加的文件
文件类型:zip 使用日期和时间_v1.1.2.zip (144.1 KB,88视图)

翻译自: https://bytes.com/topic/visual-basic/insights/913937-working-date-time

java对时间和日期的处理

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值