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

  • 相关阅读:
    IIS7中的几种身份鉴别方式(一)Basic身份验证
    IIS7中的几种身份鉴别方式(二)集成身份验证
    java集合
    SharePoint 2010中welcome page的设置细节
    SharePoint中使用Linq出现未将对象引用到实例化的解决方法
    SharePoint 2010中关于An error was encountered while retrieving the user profile的处理方式记录
    The Need for an Architectural Body of Knowledge
    The Softer Side of the Architect
    Event Receivers 学习小结
    使用SmtpClient发送带图片的邮件的代码实现
  • 原文地址:https://www.cnblogs.com/Formulate0303/p/13678291.html
Copyright © 2011-2022 走看看