123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- /**
- * 时间工具
- */
- export default class CUtilTime {
- public static getNowTime() {
- let d = new Date();
- return Math.floor(d.getTime() / 1000);
- }
- public static getNowDateInt() {
- let d = new Date();
- let curr_date = '' + d.getDate();
- let curr_month = '' + (d.getMonth() + 1);
- let curr_year = '' + d.getFullYear();
- if (curr_month.length < 2) {
- curr_month = '0' + curr_month;
- }
- if (curr_date.length < 2) {
- curr_date = '0' + curr_date;
- }
- var yyyyMMdd = curr_year + curr_month + curr_date;
- return parseInt(yyyyMMdd);
- }
- /*获取一个月的天数 */
- public static getCountDays() {
- let curDate = new Date();
- /* 获取当前月份 */
- let curMonth = curDate.getMonth();
- /* 生成实际的月份: 由于curMonth会比实际月份小1, 故需加1 */
- curDate.setMonth(curMonth + 1);
- /* 将日期设置为0, 这里为什么要这样设置, 我不知道原因, 这是从网上学来的 */
- curDate.setDate(0);
- /* 返回当月的天数 */
- return curDate.getDate();
- }
- public static getTimeString(syTime: number): string {
- let hours = Math.floor(syTime / 60 / 60); //计算剩余的小时
- let minutes = Math.floor(syTime / 60 % 60);
- let seconds = Math.floor(syTime % 60);
- let day = Math.floor(hours / 24);
- let hour = hours - day * 24;
- if (day > 0) {
- return day + '天' + hour + '小时' + minutes + '分钟' + seconds + '秒';
- }
- if (hour > 0) {
- return hour + '小时' + minutes + '分钟' + seconds + '秒';
- }
- if (minutes > 0) {
- return minutes + '分钟' + seconds + '秒';
- }
- return seconds + '秒';
- }
- public static getTimeString2(syTime: number) {
- let hours = Math.floor(syTime / 60 / 60); //计算剩余的小时
- let minutes = Math.floor(syTime / 60 % 60);
- let seconds = Math.floor(syTime % 60);
- let min = minutes > 0 && minutes < 10 ? "0" + minutes : minutes == 0 ? "00" : minutes;
- let sec = seconds > 0 && seconds < 10 ? "0" + seconds : seconds == 0 ? "00" : seconds;
- if (hours > 0) {
- return hours + ':' + min + ':' + sec;
- }
- if (minutes > 0) {
- return min + ':' + sec;
- }
- return sec;
- }
- public static _getTimeString(syTime: number): string {
- let hours = Math.floor(syTime / 60 / 60); //计算剩余的小时
- let minutes = Math.floor(syTime / 60 % 60);
- let seconds = Math.floor(syTime % 60);
- let day = Math.floor(hours / 24);
- let hour = hours - day * 24;
- if (day > 0) {
- return day + '天' + hour + '小时';
- }
- if (hour > 0) {
- return hour + '小时' + minutes + '分钟';
- }
- if (minutes > 0) {
- return minutes + '分' + seconds + '秒';
- }
- return seconds + '秒';
- }
- public static _getTimeOnlineString(syTime: number): string {
- let hours = Math.floor(syTime / 60 / 60); //计算剩余的小时
- let minutes = Math.floor(syTime / 60 % 60);
- let seconds = Math.floor(syTime % 60);
- let day = Math.floor(hours / 24);
- let hour = hours - day * 24;
- if (day > 0) {
- return day + '天';
- }
- if (hour > 0) {
- return hour + '小时';
- }
- if (minutes > 0) {
- return minutes + '分钟';
- }
- return seconds + '秒';
- }
- }
|