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