function getYear () {
let mydate = new Date();
let value = mydate.getFullYear();
return value;
}
function getMonth () {
let mydate = new Date();
let value = mydate.getMonth() + 1;
return value;
}
function getDate () {
let mydate = new Date();
let value = mydate.getDate();
return value;
}
function getDates (year, month) {
let dates = new Date(year, month, 0).getDate();
return dates;
}
- 日期格式转化1 2018,1---->2018/01
function formatDating (year, month, date) {
month = fn.addZero(month);
if (date) {
date = fn.addZero(date);
}
return year + '/' + month + (date ? '/' + date : '');
}
function formatDating2 (year, month, date) {
let mon = month.toString();
if (mon.length < 2 && month < 10) {
month = fn.addZero(month);
}
if (date) {
let dat = date.toString();
if (dat.length < 2 && date < 10) {
date = fn.addZero(date);
}
}
return year + '年' + month + '月' + (date ? date + '日' : '');
}
function getyears () {
let arr = [];
for (var i = 2000; i < 2030; i++) {
arr.push({
name: i,
value: i
})
}
return arr;
}
function getmonths () {
let arr = [];
for (var i = 1; i <= 12; i++) {
arr.push({
name: i,
value: i
})
}
return arr;
}
- 日期格式定向转化 2018/01--->2018年01月
2018/01/01->2018年01月01日
function cToe (str, type, ind) {
let restr = ''
str = str.toString();
if (ind) {
type = type == -1 || type == 2 ? type : type + 1
}
if (type == 0 || type == 3) {
//日+自定义 2018/01/01
restr = str.substring(0, 4) + '/' + str.substring(5, 7) + '/' + str.substring(8, 10) + '';
}
else if (type == 1) {
//月 2018/01
restr = str.substring(0, 4) + '/' + str.substring(5, 7) + '';
}
else if (type == 2) {
//季度 2018 第一季度
restr = str.substring(0, 4) + ' ' + str.substring(5, str.length);
}
else if (type == -1) {
//年份
str = str.toString();
restr = str.substring(0, str.length);
}
return restr;
}
fn.tochinesedate = function (params, type) {
let arr = params.split(type);
let time = arr[0] + '年' + arr[1] + '月';
return time;
}
function addZero (number) {
number = number >= 10 ? number : '0' + number
return number;
}
网友评论