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');

  • 相关阅读:
    Delphi单元文件之-防止程序重复执行
    cxGrid使用汇总2
    Delphi数组复制
    cxGrid使用汇总1
    Delphi XE5 android 获取网络状态
    xe5 android sample 中的 SimpleList 是怎样绑定的
    XE5 Android 开发数据访问手机端 解决乱码的办法
    设计模式之代理模式
    设计模式之单例模式及原型模式
    设计模式之工厂模式
  • 原文地址:https://www.cnblogs.com/koal/p/4390061.html
Copyright © 2011-2022 走看看