zoukankan      html  css  js  c++  java
  • UNIX时间戳与日期的相互转换

    mysql中UNIX时间戳与日期的相互转换

    UNIX时间戳转换为日期用函数:FROM_UNIXTIME()

    select FROM_UNIXTIME(1410318106);

    日期转换为UNIX时间戳用函数:UNIX_TIMESTAMP()

    select UNIX_TIMESTAMP('2014-09-10 11:01:46');

    where DATE_FORMAT(FROM_UNIXTIME('1410318106','%Y-%m-%d %h:%m:%s'),'%Y-%m-%d %h:%m:%s')<DATE_FORMAT(NOW(),'%Y-%m-%d %h:%m:%s')

    where FROM_UNIXTIME('1410318106','%Y-%m-%d %h:%m:%s')<DATE_FORMAT(NOW(),'%Y-%m-%d %h:%m:%s')

    oracle中UNIX时间戳与日期的相互转换

    Unix时间戳转换为Oracle时间

    create or replace function unix_to_oracle(in_number NUMBER) return date is

    begin

        return(TO_DATE('19700101','yyyymmdd') + in_number/86400 +TO_NUMBER(SUBSTR(TZ_OFFSET(sessiontimezone),1,3))/24);

    end unix_to_oracle;

    Oracle时间Date型转换为Unix时间戳

    create or replace function oracle_to_unix(in_date IN DATE) return number is

     begin return( (in_date -TO_DATE('19700101','yyyymmdd'))*86400 - TO_NUMBER(SUBSTR(TZ_OFFSET(sessiontimezone),1,3))*3600);

    end oracle_to_unix;

    Java中进行转换

    UNIX时间戳转换为日期

    Date date =new Date();

    SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    System.out.println((simpleDateFormat.parse(simpleDateFormat.format(date))).getTime()/1000);

    日期转换为UNIX时间戳

    Long timestamp = Long.parseLong("1410318106")*1000;

    String date = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new java.util.Date(timestamp));   

    System.out.println(date);

    PHP中进行转换

    UNIX时间戳转换为日期用函数: date()

    date('Y-m-d H:i:s', 1410318106);

    日期转换为UNIX时间戳用函数:strtotime()

    strtotime('2014-09-10 11:01:46');

  • 相关阅读:
    常用模板
    pascal 的字符串操作
    war2 洛谷模拟赛day2 t3 状压
    状压搜索 洛谷T47092 作业
    Milking Order
    洛谷九月月赛T1 思考
    C数列下标 牛客OI赛制测试赛2
    钓鱼 洛谷p1717
    机房人民大团结(DP)
    Spark的Straggler深入学习(2):思考Block和Partition的划分问题——以论文为参考
  • 原文地址:https://www.cnblogs.com/koal/p/4390061.html
Copyright © 2011-2022 走看看