How to convert millisecond to date format in the database _ MySQL
Source: Internet
Author: User
In the development process, we often save the number of milliseconds in the date and time to the database, but the corresponding time seems very inconvenient, some functions can be used to convert data in milliseconds to the date format.
1. in MySQL, there is a built-in function from_unixtime () for conversion, using the following:
Mysql> select from_unixtime (1, '% Y-% m-% d % H: % I: % S ');
+ --------------------------------------- +
| From_unixtime (1, '% Y-% m-% d % H: % I: % S') |
+ --------------------------------------- +
| 08:00:01 |
+ --------------------------------------- +
1 row in set (0.00 sec)
The unit of the parameter in the from_unixtime function is seconds. since we are in the + 08:00:01 time zone, all the final results are.
2. in Oracle, since there is no built-in function, we can only customize one function to complete the conversion.
SQL> create or replace function long2date (param in long) return varchar2
V_text varchar2 (64 );
2 begin
3 select to_char (to_date ('1970-01-01 ', 'yyyy-MM-DD') + (param/(24*60*60*1970) +
8/24-1/86400), 'yyyy-MM-DD HH24: MI: SS ')
4 into v_text from dual;
5 return v_text;
6 end long2date;
7/
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.