You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
1.3 KiB
35 lines
1.3 KiB
const JSEncrypt = require('../libs/jsencrypt/lib/index').default;
|
|
export function encryptedData(key, data) {
|
|
// 新建JSEncrypt对象
|
|
let encryptor = new JSEncrypt();
|
|
// 设置公钥
|
|
encryptor.setPublicKey(key);
|
|
// 加密数据
|
|
return encryptor.encrypt(data);
|
|
}
|
|
// 使用方法:
|
|
// timestampToTime(1591841249) //返回2020-06-11
|
|
// timestampToTime(1591841249,1) //返回 2020-06-11 10:10:10
|
|
// timestampToTime(1591841249,2) //返回2020年06月11日
|
|
export function timestampToTime(value, type = 0) {
|
|
var time = new Date(value);
|
|
var year = time.getFullYear();
|
|
var month = time.getMonth() + 1;
|
|
var date = time.getDate();
|
|
var hour = time.getHours();
|
|
var minute = time.getMinutes();
|
|
var second = time.getSeconds();
|
|
month = month < 10 ? '0' + month : month;
|
|
date = date < 10 ? '0' + date : date;
|
|
hour = hour < 10 ? '0' + hour : hour;
|
|
minute = minute < 10 ? '0' + minute : minute;
|
|
second = second < 10 ? '0' + second : second;
|
|
var arr = [
|
|
year + '-' + month + '-' + date,
|
|
year + '-' + month + '-' + date + ' ' + hour + ':' + minute + ':' + second,
|
|
year + '年' + month + '月' + date,
|
|
year + '年' + month + '月' + date + ' ' + hour + ':' + minute + ':' + second,
|
|
hour + ':' + minute + ':' + second
|
|
];
|
|
return arr[type];
|
|
}
|
|
|