exports.showTime=function(n){
var date=new Date(n);
var v='';
var seconds = Math.floor((new Date() - date) / 1000);
var interval = Math.floor(seconds / 31536000);
if (interval > 1) {
v= interval + " năm trước";
return v ;
}
interval = Math.floor(seconds / 2592000);
if (interval > 1) {
v= interval + " tháng trước";
return v;
}
interval = Math.floor(seconds / 86400);
if (interval > 1) {
v= interval + " ngày trước";
return v;
}
interval = Math.floor(seconds / 3600);
if (interval > 1) {
v= interval + " giờ trước ";
return v;
}
interval = Math.floor(seconds / 60);
if (interval > 1) {
v= interval + " phút trước";
return v ;
}
v= Math.floor(seconds) + " giây trước";
return v;
}
Vũ Đỗ
@Vũ Đỗ
Best posts made by Vũ Đỗ
-
RE: Hiệu thời gian Javascript
Latest posts made by Vũ Đỗ
-
RE: Hiệu thời gian Javascript
exports.showTime=function(n){ var date=new Date(n); var v=''; var seconds = Math.floor((new Date() - date) / 1000); var interval = Math.floor(seconds / 31536000); if (interval > 1) { v= interval + " năm trước"; return v ; } interval = Math.floor(seconds / 2592000); if (interval > 1) { v= interval + " tháng trước"; return v; } interval = Math.floor(seconds / 86400); if (interval > 1) { v= interval + " ngày trước"; return v; } interval = Math.floor(seconds / 3600); if (interval > 1) { v= interval + " giờ trước "; return v; } interval = Math.floor(seconds / 60); if (interval > 1) { v= interval + " phút trước"; return v ; } v= Math.floor(seconds) + " giây trước"; return v; }
-
Giúp đỡ về crop image (easyimage)
mình crop image dưới local thì chạy bthg. nhưng khi đưa lên server thì k crop được. chỉ nhận được file hình gốc ( vd: folder product có 1 hình chính, 1 folder small, 1 folder thumb. mà small vs thum lại k nhận hình). Anh/chị giúp em với.
exports.resize=function(T_src,T_dis,T_width,T_height){
var easyimg = require('easyimage'); easyimg.resize({ src:T_src, dst:T_dis, width:T_width, height:T_height, cropwidth:128, cropheight:128, x:0, y:0 }).then( function(image) { console.log('Resized and cropped: ' + image.width + ' x ' + image.height); // console.log(image); }, function (err) { throw err; console.log(err); } );
}
exports.uploadFile=function(file,name_picture,path = __dirname+'../public/upload/', pathImg = '/public/upload'){
var fs=require("fs");
var originalFilename = file.name;
var fileType = file.type.split('/')[1];
var fileSize = file.size;
var pathUpload = path + name_picture;
var pathImg = pathImg + originalFilename;
var data = fs.readFileSync(file.path);
fs.writeFileSync(pathUpload, data);
var imgUrl = '';
if( fs.existsSync(pathUpload) ) {
imgUrl = pathImg;this.resize(pathUpload,path + "small/" + name_picture,100,100); this.resize(pathUpload,path + "thumb/" + name_picture,250,250); } return imgUrl;
}