java,php,mysql时间处理
java中时间戳和时间字符串之间的转换
获取当前的unix时间戳
new Date().getTime()
System.currentTimeMillis()
返回的是毫秒数,要转换long t = System.currentTimeMillis()/1000;
获取当前年月日以及时分秒
Calendar c = Calendar.getInstance();
c.get(Calendar.YEAR)) c.get(Calendar.YEAR)) c.get(Calendar.DATE)
将UNIX时间戳转换成时间字符串
new SimpleDateFormat("yyyy/MM/dd").format(new Date(timestamp*1000));
将时间字符串转换成UNIX时间戳
new java.text.SimpleDateFormat (”dd/MM/yyyy HH:mm:ss”).parse(”09/22/2008 16:33:00″).getTime()
在java中字符串和unix时间戳之间有一个中专类型是Date
Date.getTime() 由Date到unixtime
new Date(unixtime) 由unixtime到Date
注意:
请注意!对与不同的时区处理上有差异,首先要清楚自己所在的时区。
String timezone_info = System.getProperty(”user.timezone”);
System.out.println(”当前的时区:”+timezone_info);
System.out.println(”时区信息:”+TimeZone.getDefault());
输出:
当前的时区:Asia/Shanghai
时区信息:sun.util.calendar.ZoneInfo[id="Asia/Shanghai",offset=28800000,
dstSavings=0,useDaylight=false,transitions=19,lastRule=null]
处理不同的时区的方法:
SimpleDateFormat sd = new SimpleDateFormat(”yyyy-MM-dd HH:mm:ss”);
sd.setTimeZone(TimeZone.getTimeZone(”GMT+8″));
String strDate = sd.format(new Date(1215782027390L));
System.out.println(”正八区当前时间:”+strDate);
输出:
正八区当前时间:2008-07-11 21:13:47
php中时间戳和时间字符串之间的转换
mktime()
date("format", unixtime)
time()
date('Y')
mysql中时间戳和时间字符串之间的转换
把时间字符串转为unix时间戳(格式要YYYY-mm-dd hh:ii:ss) 即数据库中timestamp生成的
UNIX_TIMESTAMP(date)
把unix时间戳转为时间字符串
DATE_FORMAT(date,format)
获取当前时间(unix时间戳)
now
根据format字符串格式化date值。
%M 月名字(January……December)
%W 星期名字(Sunday……Saturday)
%D 有英语前缀的月份的日期(1st, 2nd, 3rd, 等等。)
%Y 年, 数字,
相关文档:
create PROCEDURE pagelist
@tablename nvarchar(50),
@fieldname nvarchar(50)='*',
@pagesize int output,--每页显示记录条数
@currentpage int output,--第几页
@orderid nvarchar(50),--主键排序
@sort int,--排序方式,1表示升序,0表示降序排列
......
稳故而知新,最近又用到了,草草拿来温习一下:转自 http://www.bccn.net/Article/sjk/mysql/jc/200601/3411.html
MySQL管理员应该知道如何设置MySQL用户账号,指出哪个用户可以连接服务器,从哪里连接,连接后能做什么。MySQL
3.22.11开始引入两条语句使得这项工作更容易做:GRANT语句创建MySQL用户并指定其权限,而REV ......
LAST_INSERT_ID
自动返回最后一个 INSERT 或 UPDATE 操作为 AUTO_INCREMENT 列设置的第一个发生的值. 参考这里
The ID that was generated is maintained in the server on a per-connection basis.
LAST_INSERT_ID是基于单个connection的, 不可能被其它的客户端连接改变。
可以用 SELECT LAST_INSERT_ID(); 查询LAST ......
注:本文讨论的范围为未启用MAXDB模式的表!
今天建了一个表,里面有一个列是timestamp类型,我本意是在数据更新时,这个字段的时间能自动更新。岂知对这个类型的值还不甚了解,导致出错。发现这个字段只是在这行数据建立的时候有值,在更新的却无变化。
查找资料,发现是我 ......