显示当前时间(EST) [英] Show current time (EST)
本文介绍了显示当前时间(EST)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了一个UserForm,其中包含一个文本框,该文本框将显示EST的当前时间。唯一的问题是,反映的时间当然是我们国家/地区的当前时间,因此我想将其转换为EST,即我们当前时间的-12:00
。
I created a UserForm that contains a textbox that will show the current time in EST. The only problem is, the time that's reflecting is of course the current time in our country so I want to convert it in EST, which is - 12:00
from our time.
Private Sub UserForm_Initialize()
If ActiveWorkbook.MultiUserEditing Then
End If
Application.ScreenUpdating = False
Application.DisplayAlerts = False
txtDate.Value = Format(Now, "mm/dd/yyyy")
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
推荐答案
比R3uK更复杂的方法,但我一直首选使用 TimeSerial()
和 DateSerial()
获取我的确切标准设置(尤其是当您需要修改时间的多个部分时)。
A more complicated way than R3uK but I've always preferred using TimeSerial()
and DateSerial()
to get my exact criteria setup (especially when you need to modify multiple parts of the Time).
Sub TimeToEST()
Dim ESTHour As Integer
If Hour(Now) - 12 < 0 Then
ESTHour = 24 + Hour(Now) - 12
Else
ESTHour = Hour(Now) - 12
End If
txtDate.Value = TimeSerial(ESTHour, Minute(Now), Second(Now))
End Sub
仅显示EST中的当前日期:
To show just the current date in EST:
Sub DateToEST()
Dim ESTDate As Date
If Hour(Now) < 12 And Day(Now) = 1 Then
ESTDate = Now - TimeValue("12:00:00")
ElseIf Hour(Now) < 12 Then
ESTDate = DateSerial(Year(Now), Month(Now), Day(Now) - 1)
Else
ESTDate = DateSerial(Year(Now), Month(Now), Day(Now))
End If
txtDate.Value = ESTDate
End Sub
这篇关于显示当前时间(EST)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文