1. now()
         
     select now();
    结果:2021-04-23 14:29:50.043339+08

    返回 年-月-日 时:分:秒.毫秒+时区

  2. current_timestamp效果是和now()一样的。
    select current_timestamp;
    结果:2021-04-23 14:32:28.865183+08

    返回 年-月-日 时:分:秒.毫秒+时区

  3. current_date
    select current_date;
    结果:2021-04-23
    返回 日期-年月日
     
  4. current_time
    select current_time;
    结果:14:33:36.645919+08

    返回 时间-时分秒毫秒+时区

  5. 时间格式转换

    --timestamp(num) num表示毫秒保留数 
    select now()::timestamp(0)without time zone
  6. 获取系统当前时间毫秒数的sql,以及秒级时间戳

    1、这个比较准确
    
    select floor(extract(epoch from now()));
    
    
    2、获取数据库中毫秒级
    
    select floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)));
    
    
    3、获取系统中秒级的时间
    
    select floor(extract(epoch from(current_timestamp - timestamp '1970-01-01 00:00:00')));

     

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐