zoukankan      html  css  js  c++  java
  • mysql—MySQL数据库中10位或13位时间戳和标准时间相互转换

    
    

    1、字符串时间转10位时间戳

    select FLOOR(unix_timestamp(create_time)) from page;  #create_time为字段名   page为表名
    eg:select FLOOR(UNIX_TIMESTAMP('2020-06-30')) from `boc_circle` #结果为1593446400 /*2020-08-31   1598803200   2020-07-01 1593532800   2020-09-01 1598889600  2020-06-30 1593446400*/

    2、10位时间戳转日期类型

    select  FROM_UNIXTIME(time_ms) from page ;  #time_ms为字段名  page为表名
    select  FROM_UNIXTIME(time_ms,format) from page ;  #将MYSQL中以INT(11)存储的时间以"YYYY-MM-DD"格式来显示。time_ms为字段名 page为表名 format格式

    eg:
    select FROM_UNIXTIME(1593532800) from `boc_circle_post`   #结果为2020-07-01 00:00:00 
    <=>
    select FROM_UNIXTIME(1593532800, '%Y-%m-%d %H:%i:%S')from `boc_circle_post` #结果为2020-07-01 00:00:00
    select FROM_UNIXTIME(1593532800,'%Y-%m-%d')from `boc_circle_post` #结果为2020-07-01 
    PS:下列修饰符可以被用在format字符串中
    %M 月名字(January……December)
    %W 星期名字(Sunday……Saturday)
    %D 有英语前缀的月份的日期(1st, 2nd, 3rd, 等等。)
    %Y 年, 数字, 4 位
    %y 年, 数字, 2 位
    %a 缩写的星期名字(Sun……Sat)
    %d 月份中的天数, 数字(00……31)
    %e 月份中的天数, 数字(0……31)
    %m 月, 数字(01……12)
    %c 月, 数字(1……12)
    %b 缩写的月份名字(Jan……Dec)
    %j 一年中的天数(001……366)
    %H 小时(00……23)
    %k 小时(0……23)
    %h 小时(01……12)
    %I 小时(01……12)
    %l 小时(1……12)
    %i 分钟, 数字(00……59)
    %r 时间,12 小时(hh:mm:ss [AP]M)
    %T 时间,24 小时(hh:mm:ss)
    %S 秒(00……59)
    %s 秒(00……59)
    %p AM或PM
    %w 一个星期中的天数(0=Sunday ……6=Saturday )
    %U 星期(0……52), 这里星期天是星期的第一天
    %u 星期(0……52), 这里星期一是星期的第一天
    %% 一个文字“%”

    3、13位时间戳转日期类型

    select  FROM_UNIXTIME(round(time_ms/1000,0)) from page ; #time_ms为字段名   page为表名

    PS:以上也可以在dual 系统自带文件上查询时间,例如:
    select FLOOR(UNIX_TIMESTAMP('2020-09-30')) from dual

  • 相关阅读:
    el自定义函数库
    DOM4J
    【转载】SqlServer日期时间函数
    【原创】C#认识/理解/运用 StreamReader,StreamWriter,StringReader,StreamWriter
    【原创】C#认识/理解/运用 FileStream
    【原创】C#操作XML(带命名空间)
    【原创】ASP.NET MVC3使用html编辑器(kindeditor)
    【原创】ASP.NET MVC3 从零开始一步步构建Web
    【转载】MVC使用jqGrid
    【原创】C#使用HttpWebRequest,HttpWebResponse
  • 原文地址:https://www.cnblogs.com/Formulate0303/p/13678291.html
Copyright © 2011-2022 走看看