;- DST = example calculate CEST Central-European- SUMMER Time
;-
https://autohotkey.com/boards/viewtopic.php?f=28&t=46997
;-
;-
https://www.timeanddate.com/time/dst/
;-
https://www.timeanddate.com/worldclock/
;-
https://www.science.co.il/language/Locale-codes.php
; ( UTC + 1 / CET - Central European Time - begin last sunday in octobre / e.g sun 2018-10-28 03:00>02:00 UTC 01:00)
; ( UTC + 2 / CEST - Central European SUMMER Time - begin last sunday in mars / e.g. sun 2018-03-25 02:00>03:00 UTC 01:00)
;-
https://en.wikipedia.org/wiki/Summer_Time_in_Europe
;- On 8 February 2018, the European Parliament voted to ask the European Commission to re-evaluate DST in Europe.
;- On 31 August 2018, the European Commission announced that they, after a web query giving high support of not switching clock twice annually, intend to go ahead with a new directive.
;-
A formula which cn be used to calculate the beginning of European Summer Time is:
Sunday (31 − ((((5 × y) ÷ 4) + 4) mod 7)) March at 01:00 UTC
The corresponding formula for the end of European Summer Time is:
Sunday (31 − ((((5 × y) ÷ 4) + 1) mod 7)) October at 01:00 UTC
where y is the year, and a mod b is b times the fractional part of a/b. These formulae are valid until 2099
;-
;- Function last sunday in mars and october for DST daylight saving time ( example EUROPE )
;-
https://autohotkey.com/board/topic/97664-find-specific-wday/ ---
Code: Select all
;- Function last sunday in mars and october for DST daylight saving time
;- https://autohotkey.com/board/topic/97664-find-specific-wday/ ---
LastSunday(Date)
{
Date += 31, D
Date := SubStr(Date, 1, 6)
Date += -1, Day
FormatTime, WD , %Date%, WDay
Date += -(WD - 1), D
return, SubStr(Date, 1, 8)
}
a script from
@tmplinshi , get UTC and add 1 or 2 hours for CET or CEST ( EUROPE - SET TIME )
or use original script from tmplinshi to set China Time , UTC + 8 hours
;-
Code: Select all
;- https://autohotkey.com/boards/viewtopic.php?f=28&t=46997 ---
;- https://www.timeanddate.com/time/dst/
;- https://www.timeanddate.com/worldclock/
;- https://www.science.co.il/language/Locale-codes.php
;- 歐洲 CET / CEST Central European Summer-Time
;-----------------------------------------------------
#warn
setworkingdir,%a_scriptdir%
; 以管理员身份运行
if !A_IsAdmin {
Try
Run *RunAs "%A_ScriptFullPath%" ; Requires v1.0.92.01+
ExitApp
}
global dst
if SynTime.DoIt()
msgbox, 262208,SUCCESS ,Succes synchronized %dst%,
else
msgbox, 262208,NO SUCCESS , NO Succes synchronized CET,
return
/*
if SynTime.DoIt()
MsgBox, 64, 成功 , 同步北京时间成功!
else
MsgBox, 48, 失败 , 同步失败!
; 同步北京时间。用法: SynTime.DoIt()
return
*/
Class SynTime
{
DoIt() { ; 成功返回 1
return this.SetLocalTime( this.BeijingTime() )
}
SetLocalTime(YYYYMMDDHHMISS) {
FormatTime, t, %YYYYMMDDHHMISS%, yyyy/M/1/d/H/m/s/0
VarSetCapacity(SystemTime, 16, 0)
Loop, Parse, t, /
NumPut(A_LoopField, SystemTime, (A_Index-1)*2, "UShort")
return DllCall("SetLocalTime", "Ptr", &SystemTime)
}
BeijingTime() { ; 返回 YYYYMMDDHHMISS
whr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
whr.Open("HEAD", "http://baidu.com", true)
whr.Send()
whr.WaitForResponse()
_date := whr.GetResponseHeader("Date") ; 示例数据: Mon, 21 Apr 2014 14:58:23 GMT
arr := StrSplit( _date, [A_Space, ":"] )
oMonth := {Jan:"01",Feb:"02",Mar:"03",Apr:"04",May:"05",Jun:"06",Jul:"07",Aug:"08",Sep:"09",Oct:"10",Nov:"11",Dec:"12"}
Mon := oMonth[ arr.3 ] ; 月份英文缩写转换成数字
timestamp := arr.4 Mon arr.2 arr.5 arr.6 arr.7 ; YYYYMMDDHHMISS 格式的日期
p2:=1 ;- ( UTC + 1 / CET - Central European Time - begin last sunday in octobre / e.g sun 2018-10-28 03:00>02:00 )
stringmid,q,timestamp,1,8
stringmid,Y,timestamp,1,4
q:=(q)
lsm := LastSunday(Y . "03")
lso := LastSunday(Y . "10")
if (q >= lsm) and (q < lso)
{
DST:="CEST summertime UTC+2"
p2:=(P2+1) ;- ( UTC + 2 / CEST - Central European SUMMER Time - DST begin last sunday in mars / e.g. sun 2018-03-25 02:00>03:00 )
timestamp += +P2,hours
}
else
{
DST:="CET normaltime UTC+1"
timestamp += +P2,hours
}
;timestamp += 8, Hours ; 加 8 小时就是北京时间
return timestamp
}
}
;-----------------------------------------------------------------------
;- Function last sunday in mars and october for DST daylight saving time in Europe
;- https://autohotkey.com/board/topic/97664-find-specific-wday/ ---
LastSunday(Date)
{
Date += 31, D
Date := SubStr(Date, 1, 6)
Date += -1, Day
FormatTime, WD , %Date%, WDay
Date += -(WD - 1), D
return, SubStr(Date, 1, 8)
}
;============================================================================