firemail

标题: 基于毫秒级日期的数据库字段设计 [打印本页]

作者: java    时间: 2017-3-30 14:52
标题: 基于毫秒级日期的数据库字段设计
本帖最后由 java 于 2017-11-23 11:15 编辑
  1. CREATE TABLE `test_keys` (
  2.   `id` INT(11) NOT NULL AUTO_INCREMENT
  3.   `name` VARCHAR(64) NOT NULL COMMENT '名称'
  4.   `create_time` BIGINT(20) DEFAULT NULL,
  5.   `modify_time` BIGINT(20) DEFAULT NULL,
  6.   PRIMARY KEY (`id`),
  7.   INDEX `idx_classification` (`modify_time` ASC)
  8. ) ENGINE=INNODB AUTO_INCREMENT=1 DEFAULT CHARSET=UTF8 COLLATE = UTF8_BIN;


  9. insert into test_keys(name, create_time, modify_time) values('xxxx', UNIX_TIMESTAMP(now(3))*1000, UNIX_TIMESTAMP(now(3))*1000);

  10. select from_unixtime(modify_time/1000) from test_keys;
复制代码
update ad set begin_time = unix_timestamp('2016-01-02 12:12:12.001')*1000 where id = 55;
select from_unixtime(begin_time/1000), begin_time from ad where id = 55;    查看结果-- '2016-01-02 12:12:12.0010', '1451707932001'

select CONCAT('''', order_id) as order_id, FROM_UNIXTIME(modify_time/1000) as modify_time,FROM_UNIXTIME(modify_time/1000,'%Y-%c-%d %h:%i:%s') as timedd  from v_order order by modify_time desc limit 0,10

作者: linux    时间: 2017-4-11 16:12
本帖最后由 linux 于 2017-4-11 18:13 编辑
  1. <resultMap id="BaseResultMap" type="com.ktionKeys"
  2.     <result column="create_time" jdbcType="BIGINT" property="createTime" />
  3.     <result column="modify_time" jdbcType="BIGINT" property="modifyTime" />
  4.   </resultMap>
复制代码
  1. <table id="welfareDetailTable" class="table">
  2.         <thead>
  3.         <tr>
  4.             <th>标题</th>
  5.             <th>编码</th>
  6.             <th>状态</th>
  7.             <th>创建时间</th>
  8.             <th>修改时间</th>
  9.             <th style="width: 200px;"></th>
  10.         </tr>
  11.         </thead>
  12.         <tbody>
  13.         <#list welfareBvo.welfareList as welfare>
  14.         <tr>
  15.             <td>${(welfare.title)!''}</td>
  16.             <td>${(welfare.code)!''}</td>
  17.             <td>${(welfare.status)!''}</td>
  18.             <td> ${(welfare.createTime)?number_to_datetime}</td>
  19.             <td> ${(welfare.modifyTime)?number_to_datetime}</td>
  20.             <td>
  21.                 <a href="javascript:void(0);" onclick="updateWelfare(${welfare.id})" title="修改"><i class="icon-pencil"></i></a> |
  22.                 <a href="javascript:void(0);" onclick="deleteWelfare(${welfare.id})" title="删除"><i class="icon-remove"></i></a>
  23.             </td>
  24.         </tr>
  25.         </#list>
  26.         </tbody>
  27.     </table>
复制代码

作者: java    时间: 2017-6-29 09:48
本帖最后由 java 于 2017-6-29 09:50 编辑

涉及的函数date_format(date, format) 函数,MySQL日期格式化函数date_format()
unix_timestamp() 函数
str_to_date(str, format) 函数
from_unixtime(unix_timestamp, format) 函数,MySQL时间戳格式化函数from_unixtime
时间转字符串
时间转时间戳
字符串转时间
字符串转时间戳
时间戳转时间
时间戳转字符串
附表
[size=1em]MySQL日期格式化(format)取值范围。
含义
%S、%s两位数字形式的秒( 00,01, ..., 59)
%I、%i两位数字形式的分( 00,01, ..., 59)
小时 %H24小时制,两位数形式小时(00,01, ...,23)
%h12小时制,两位数形式小时(00,01, ...,12)
%k24小时制,数形式小时(0,1, ...,23)
%l12小时制,数形式小时(0,1, ...,12)
%T24小时制,时间形式(HH:mm:ss)
%r 12小时制,时间形式(hh:mm:ss AM 或 PM)
%p AM上午或PM下午
  周 %W一周中每一天的名称(Sunday,Monday, ...,Saturday)
%a一周中每一天名称的缩写(Sun,Mon, ...,Sat)
%w 以数字形式标识周(0=Sunday,1=Monday, ...,6=Saturday)
%U数字表示周数,星期天为周中第一天
%u数字表示周数,星期一为周中第一天
%d 两位数字表示月中天数(01,02, ...,31)
%e 数字表示月中天数(1,2, ...,31)
%D英文后缀表示月中天数(1st,2nd,3rd ...)
%j以三位数字表示年中天数(001,002, ...,366)
%M 英文月名(January,February, ...,December)
%b 英文缩写月名(Jan,Feb, ...,Dec)
%m 两位数字表示月份(01,02, ...,12)
%c 数字表示月份(1,2, ...,12)
%Y 四位数字表示的年份(2015,2016...)
%y 两位数字表示的年份(15,16...)
文字输出 %文字 直接输出文字内容

http://www.cnblogs.com/jhy-ocean/p/5560857.html













欢迎光临 firemail (http://www.firemail.wang:8088/) Powered by Discuz! X3