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

  • 相关阅读:
    软件的分解-编程语言自带分解功能
    面向接口编程定义了软件的生长方式
    软件开发的分:分离、分解、分类
    软件开发的分离之术-软件易变性的应对之道
    软件的本质
    软件开发的核心问题-三次转换
    没有银弹-软件工程中的根本和次要问题
    软件复杂性的通俗理解
    软件的复杂性与构造定律
    软件复杂性
  • 原文地址:https://www.cnblogs.com/koal/p/4390061.html
Copyright © 2011-2022 走看看