找回密码
 加入
搜索
查看: 2797|回复: 4

[系统综合] mysql中取出来的时间值怎么转换为现在时间【已解决】

[复制链接]
发表于 2012-11-21 11:29:48 | 显示全部楼层 |阅读模式
本帖最后由 shuaiw 于 2012-11-22 14:37 编辑

我在mysql中取出来的值时一串数字,这串数字是以1970年一月一日,零点零分零秒开始算到当前时刻的时间的偏移,请问下有没有人能够帮忙解决下这个偏移怎么算。我知道有一个函数是可以解决这个问题,但是不会使用这个函数。函数为localtime,是vc系统带的函数,我决定是可以使用的,求高手帮忙
发表于 2012-11-21 12:50:35 | 显示全部楼层
_DateDiff('d', $now, _NowCalc())
 楼主| 发表于 2012-11-21 14:29:25 | 显示全部楼层
不好意思,我表达错了,我是想要一个函数能把这个偏移量换位当前时间的,就是数据库给我的是一个时间的偏移量,我怎么把这个偏移量换算成为生成这条记录的当前时间。
 楼主| 发表于 2012-11-22 14:35:46 | 显示全部楼层
为什么我自己换算发现数据库中存的时间换算成普通时间之后会相差32小时啊
 楼主| 发表于 2012-11-22 14:37:07 | 显示全部楼层
换算代码已经写好了,和大家分享下
#Include <Date.au3>
$time=$time1+115200
$time_year0=Floor($time/31536000);$time_year为到现在为止的过的年
$time_year=$time_year0+1970
$a=0
For $i=0 To  $time_year0-1 Step +1
If _DateIsLeapYear($i+1970) Then
        $a=$a+1
EndIf
Next
$lun=_DateDaysInMonth($time_year,2)
$time_year1=$time-($time_year0*31536000)-($a*86400)
$time_day1=Floor ($time_year1/86400)
Select
Case $time_day1<=31
                $time_mon=1
        $time_day= $time_day1
Case $time_day1-31<=$lun
        $time_mon=2
        $time_day= $time_day1-31
Case $time_day1-31-$lun<=31
        $time_mon=3
        $time_day=$time_day1-31-$lun
Case $time_day1-31-$lun-31<=30
        $time_mon=4
        $time_day=$time_day1-31-$lun-31
Case $time_day1-31-$lun-31-30<=31       
        $time_mon=5
        $time_day=$time_day1-31-$lun-31-30
Case $time_day1-31-$lun-31-30-31<=30       
        $time_mon=6
        $time_day=$time_day1-31-$lun-31-30-31
Case $time_day1-31-$lun-31-30-31-30<=31       
        $time_mon=7
        $time_day=$time_day1-31-$lun-31-30-31-30
Case $time_day1-31-$lun-31-30-31-30-31<=31       
        $time_mon=8
        $time_day=$time_day1-31-$lun-31-30-31-30-31
Case $time_day1-31-$lun-31-30-31-30-31-31<=30       
        $time_mon=9
        $time_day=$time_day1-31-$lun-31-30-31-30-31-31
Case $time_day1-31-$lun-31-30-31-30-31-31-30<=31       
        $time_mon=10
        $time_day=$time_day1-31-$lun-31-30-31-30-31-31-30
Case $time_day1-31-$lun-31-30-31-30-31-31-30-31<=30
        $time_mon=11
        $time_day=$time_day1-31-$lun-31-30-31-30-31-31-30-31
Case $time_day1-31-$lun-31-30-31-30-31-31-30-31-30<=31       
        $time_mon=12
        $time_day=$time_day1-31-$lun-31-30-31-30-31-31-30-31-30
EndSelect       
$time_hour=Floor(($time_year1-$time_day1*86400)/3600)
$time_min1=($time_year1-$time_day1*86400)-$time_hour*3600
$time_min=Floor ($time_min1/60)
$time_s=$time_min1-$time_min*60
MsgBox(4096,"",$time_year&"-"&$time_mon&"-"&$time_day&"-"&$time_hour&"-"&$time_min&"-"&$time_s)
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-11-17 06:43 , Processed in 0.083318 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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