找回密码
 加入
搜索
查看: 11777|回复: 5

[AU3基础] (已解决)知道@year&@yday怎么计算它的@year&@mon@mday

  [复制链接]
发表于 2013-9-18 16:09:23 | 显示全部楼层 |阅读模式
本帖最后由 scorpio1102 于 2013-9-20 08:22 编辑

如题:比如20130918是13年的261天,那么2013261转换成20130918怎么写,给个思路吧.
发表于 2013-9-18 16:49:16 | 显示全部楼层
Local $iday = 261
$sJulDate = _DateToDayValue (2013, 1, 1)
Dim $Y, $M, $D
$sJulDate = _DayValueToDate ($sJulDate+$iday, $Y, $M, $D)
MsgBox(4096, "", "14 days ago:" & $M & "/" & $D & "/" & $Y & " ?(" & $sJulDate & ")")
发表于 2013-9-19 21:16:46 | 显示全部楼层
这是2013261转换成20130918的数学转换方式,并不是楼上的代码,只是我从代码中知道可能看_DayValueToDate可以知道数学方式。
鉴定如下,楼上答非所问
发表于 2013-9-19 22:31:04 | 显示全部楼层
本帖最后由 xms77 于 2013-9-19 22:37 编辑

回复 1# scorpio1102
笨办法就是凑日子来算,呵呵!

#include <Date.au3>

Local $Date = _Date_Countday2Date(2012366)
MsgBox(0, 0, $Date)

Func _Date_Countday2Date($iCountDay)
        Local $Month[12] = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"]
        Local $MDay[31] = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31"]
        If Not StringRegExp($iCountDay, "\d+", 0) Then Return MsgBox(16, "Error", '数据无效')
        Local $Year = StringLeft($iCountDay, 4)
        Local $CountDay = Int(StringTrimLeft($iCountDay, 4))
        If $CountDay > 366 Then Return MsgBox(16, "Error", '数据无效')
        For $i = 0 To 11
                For $j = 0 To 30
                        If _DateDiff('D', $Year & "/01/01", $Year & "/" & $Month[$i] & "/" & $MDay[$j]) = $CountDay-1 Then
                                Return $Year & $Month[$i] & $MDay[$j]
                        EndIf
                Next
        Next
EndFunc   ;==>_Date_Countday2Date
发表于 2013-9-19 22:41:03 | 显示全部楼层
本帖最后由 user3000 于 2013-9-19 22:43 编辑

2楼的思路复杂化了. 直接以 2013/1/1 加天数就得出结果了.
当然,如果要分别得到年月日三个变量的值, 还是用2楼的代码吧
2013/09/18 是第260天.
#include 'date.au3'
Local $iday = 260
MsgBox(0, '', _DateAdd('D', $iday, '2013/1/1'))
 楼主| 发表于 2013-9-20 08:14:02 | 显示全部楼层
本帖最后由 scorpio1102 于 2013-9-20 08:24 编辑

多谢各位的集思广益,以下是参考2楼与帮助手册解的方法.
#include <Date.au3>
; (Julian date).
;consolewrite(@MON)
;consolewrite(@MDAY)
Local $sJulDate = _DateToDayValue(@YEAR, '01', '01')
MsgBox(4096, "", "Todays Julian date is: " & $sJulDate)

Local $Y, $M, $D
$sJulDate = _DayValueToDate($sJulDate+@YDAY-1, $Y, $M, $D)
MsgBox(4096, "", "what date is it @year&@yday:" & $M & "/" & $D & "/" & $Y & "  (" & $sJulDate & ")")

4楼也辛苦了.
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-9-28 21:20 , Processed in 0.084957 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表