
可以生成具体时间的时间戳例如 2011-07-01 15:00:38 生成指定日期的时间戳 具体你可以参造一下php手册的time函数--这个是生成当前时间的时间戳date函数---这个可以生成指定日期及格式化日期mktime函数---这个函数是生成指定日期的时间戳的
PHP 的 time() 函数返回的结果是 Unix 时间戳,值的单位是秒;
Java 中 SystemcurrentTimeMillis() 返回的结果,值的单位是毫秒。
那么很容易就知道,除以 1000 就行了嘛:
int seconds = SystemcurrentTimeMillis() / 1000;时间戳的概念:它是一种时间表示方式,定义为从格林威治时间1970年01月01日00时00分00秒(北京时间1970年01月01日08时00分00秒)起至现在的总秒数。
下图是从linux系统中获得当前时间戳的一种方式
在oracle使用时间戳,一般都是为了方便计算时间差的,我们要知道oracle中的date类型想减是不能友好的得到时间的差值的。所以使用时间戳来得到两个时间差。
首先来看oracle中如何获得当前时间的时间戳,我们用当前时间减去计算机元年后再经过换算得到了的从1970年来到当前时间的时间戳,单位是微妙。
另外oracle提供了另一种便捷得到两个时间差的方式,那就是使用timestamp数据类型,它类似date类型,但是存储的时间更为精确,显示的格式:yyyy-mm-dd hh24:mi:ssff AM,其中ff是小数秒。
timestamp类型的时间差可读性也比上面那种好一些,可以直观看出两个时间差。
在oracle中,两个date类型的数值想减也可以转换成上述的timestamp可以的类型,这里就要介绍一个函数:numtodsinterval(n,'x'),它能将一个数值转换成timestamp那种格式的数据。但要注意:后面的参数'x'是取'day'、'minute'、'hour'完全取决于前面的单位,这样才能获得正确的时间差
6
最后我们介绍一个函数extract,该函数可以从timestamp类型的时间里抽取想要hour,minute等
1MySQL获得当前时间戳函数:current_timestamp,current_timestamp()mysql>selectcurrent_timestamp,current_timestamp();+---------------------+---------------------+|current_timestamp|current_timestamp()|+---------------------+---------------------+|2008-08-0923:22:24|2008-08-0923:22:24|+---------------------+---------------------+2MySQL(Unix时间戳、日期)转换函数:unix_timestamp(),unix_timestamp(date),from_unixtime(unix_timestamp),from_unixtime(unix_timestamp,format)下面是示例:selectunix_timestamp();--1218290027selectunix_timestamp('2008-08-08');--1218124800selectunix_timestamp('2008-08-0812:30:00');--1218169800selectfrom_unixtime(1218290027);--'2008-08-0921:53:47'selectfrom_unixtime(1218124800);--'2008-08-0800:00:00'selectfrom_unixtime(1218169800);--'2008-08-0812:30:00'selectfrom_unixtime(1218169800,'%Y%D%M%h:%i:%s%x');--'20088thAugust12:30:002008'3MySQL时间戳(timestamp)转换、增、减函数:timestamp(date)--datetotimestamptimestamp(dt,time)--dt+timetimestampadd(unit,interval,datetime_expr)--timestampdiff(unit,datetime_expr1,datetime_expr2)--请看示例部分:selecttimestamp('2008-08-08');--2008-08-0800:00:00selecttimestamp('2008-08-0808:00:00','01:01:01');--2008-08-0809:01:01selecttimestamp('2008-08-0808:00:00','1001:01:01');--2008-08-1809:01:01selecttimestampadd(day,1,'2008-08-0808:00:00');--2008-08-0908:00:00selectdate_add('2008-08-0808:00:00',interval1day);--2008-08-0908:00:00MySQLtimestampadd()函数类似于date_add()。selecttimestampdiff(year,'2002-05-01','2001-01-01');---1selecttimestampdiff(day,'2002-05-01','2001-01-01');---485selecttimestampdiff(hour,'2008-08-0812:00:00','2008-08-0800:00:00');---12selectdatediff('2008-08-0812:00:00','2008-08-0100:00:00');--7MySQLtimestampdiff()函数就比datediff()功能强多了,datediff()只能计算两个日期(date)之间相差的天数。
以上就是关于php 时间戳,能够取得具体时间量的时间错值吗例如10分钟的时间戳是多少刚接触php,谢谢了。全部的内容,包括:php 时间戳,能够取得具体时间量的时间错值吗例如10分钟的时间戳是多少刚接触php,谢谢了。、请问Java怎么获得当前时间戳,要int型的不要long的!、plsql怎么取时间为时间戳等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)