IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 游戏开发 -> 脚本(一)计算同环比时间 -> 正文阅读

[游戏开发]脚本(一)计算同环比时间

该脚本是用于在js中计算各种类型的同环比时间,输入时间格式为 yyyy-MM,输出为各种格式的同环比时间字符串。

//拆解出查询条件中的年、月
var datetime = new Date(selected_month_time)
var year = datetime.getFullYear()
var month = datetime.getMonth() + 1

//当天凌晨时间戳,并拆解出当天年、月、日
var todayDateTime = new Date(new Date().toLocaleDateString())
var todayYear = todayDateTime.getFullYear()
var todayMonth = todayDateTime.getMonth() + 1
var todayDay = todayDateTime.getDate()

//判断查询是否为当月
var isCurrentMonth = false
if( year===todayYear && month===todayMonth){
    isCurrentMonth = true
}

//查询月份的起止时间
var selected_start_date = selected_month_time + '-01 00:00:00'
var selected_stop_date = addMonthOrGetNow(year,month,isCurrentMonth,todayYear,todayMonth,todayDay)
var selected_start_date_day = selected_start_date.substring(0,10)
var selected_stop_date_day = selected_stop_date.substring(0,10)
var selected_start_date_month = selected_start_date.substring(0,7)
var selected_stop_date_month = getStopMonth(isCurrentMonth,selected_stop_date.substring(0,7))
console.log("selected_start_date",selected_start_date);
console.log("selected_stop_date",selected_stop_date);
console.log("selected_start_date_day",selected_start_date_day);
console.log("selected_stop_date_day",selected_stop_date_day);
console.log("selected_start_date_month",selected_start_date_month);
console.log("selected_stop_date_month",selected_stop_date_month);
console.log("bq_month",month);
console.log("bq_last_day",getLastDay(year,month));

//同比查询月份的起止时间
var tb_selected_start_date = tbDateStr(selected_start_date)
var tb_selected_stop_date = tbDateStr(selected_stop_date)
var tb_selected_start_date_day = tb_selected_start_date.substring(0,10)
var tb_selected_stop_date_day = tb_selected_stop_date.substring(0,10)
var tb_selected_start_date_month = tb_selected_start_date.substring(0,7)
var tb_selected_stop_date_month = getStopMonth(isCurrentMonth,tb_selected_stop_date.substring(0,7))
console.log("tb_selected_start_date",tb_selected_start_date);
console.log("tb_selected_stop_date",tb_selected_stop_date);
console.log("tb_selected_start_date_day",tb_selected_start_date_day);
console.log("tb_selected_stop_date_day",tb_selected_stop_date_day);
console.log("tb_selected_start_date_month",tb_selected_start_date_month);
console.log("tb_selected_stop_date_month",tb_selected_stop_date_month);

//环比查询月份的起止时间
var hb_selected_start_date = hbDateStr(selected_start_date)
var hb_selected_stop_date = hbDateStr(selected_stop_date)
var hb_selected_start_date_day = hb_selected_start_date.substring(0,10)
var hb_selected_stop_date_day = hb_selected_stop_date.substring(0,10)
var hb_selected_start_date_month = hb_selected_start_date.substring(0,7)
var hb_selected_stop_date_month = getStopMonth(isCurrentMonth,hb_selected_stop_date.substring(0,7))
console.log("hb_selected_start_date",hb_selected_start_date);
console.log("hb_selected_stop_date",hb_selected_stop_date);
console.log("hb_selected_start_date_day",hb_selected_start_date_day);
console.log("hb_selected_stop_date_day",hb_selected_stop_date_day);
console.log("hb_selected_start_date_month",hb_selected_start_date_month);
console.log("hb_selected_stop_date_month",hb_selected_stop_date_month);

//计算近一年的本期、同期、环期的起止时间(只到天)
var select_start_data_recent_oneyear = tb_selected_start_date.substring(0,10)
var select_stop_data_recent_oneyear = selected_start_date.substring(0,10)
console.log('select_start_data_recent_oneyear',select_start_data_recent_oneyear)
console.log('select_stop_data_recent_oneyear',select_stop_data_recent_oneyear)

var tb_select_start_data_recent_oneyear = tbDateStr(tb_selected_start_date).substring(0,10)
var tb_select_stop_data_recent_oneyear = select_start_data_recent_oneyear
console.log('tb_select_start_data_recent_oneyear',tb_select_start_data_recent_oneyear)
console.log('tb_select_stop_data_recent_oneyear',tb_select_stop_data_recent_oneyear)

var hb_select_start_data_recent_oneyear = tbDateStr(hbDateStr(selected_start_date)).substring(0,10)
var hb_select_stop_data_recent_oneyear = hbDateStr(selected_start_date).substring(0,10)
console.log('hb_select_start_data_recent_oneyear',hb_select_start_data_recent_oneyear)
console.log('hb_select_stop_data_recent_oneyear',hb_select_stop_data_recent_oneyear)


function addMonthOrGetNow(year, month,isCurrentMonth,todayYear,todayMonth,todayDay) {
    if(isCurrentMonth){
        if(todayMonth<10){
            todayMonth = '0' + todayMonth
        }
        if(todayDay<10){
            todayDay = '0' + todayDay
        }
        return '' + todayYear + '-' + todayMonth + '-' + todayDay + ' 00:00:00'
    }else{
        if(month===12){
            year = year + 1
            month = 1
        }else{
            month = month + 1
        }
        if(month<10){
            month = '0' + month
        }
        return '' + year + '-' + month + '-01 00:00:00'
    }
    

}

function tbDateStr(selected_date){
    var datetime = new Date(selected_date)
    var year = datetime.getFullYear()
    year = year - 1
    return '' + year + selected_date.substring(4)
}

function hbDateStr(selected_date){
    var datetime = new Date(selected_date)
    var year = datetime.getFullYear()
    var month = datetime.getMonth() + 1

    if(month===1){
        year = year - 1
        month = 12
    }else{
        month = month - 1
    }
    if(month<10){
        month = '0' + month
    }
    
    return '' + year + '-' + month + selected_date.substring(7)
}


function getStopMonth(isCurrentMonth,stop_date_month) {
    var year = parseInt(stop_date_month.substring(0,4))
    var month = parseInt(stop_date_month.substring(5,7))
    if(isCurrentMonth){
        if(month==12){
            month = 1
            year = year + 1
        }else{
            month = month + 1
        }

        if(month<10){
            return '' + year + '-0' + month 
        }else{
            return '' + year + '-' + month 
        }
    }else{
        return stop_date_month
    }
}

function getLastDay(year,month){
    var lastDateTime = new Date(year,month,0)
    var bq_last_day = lastDateTime.getDate()
    if(bq_last_day<10){
        return '0' + bq_last_day
    }else{
        return '' + bq_last_day
    }
}

  游戏开发 最新文章
6、英飞凌-AURIX-TC3XX: PWM实验之使用 GT
泛型自动装箱
CubeMax添加Rtthread操作系统 组件STM32F10
python多线程编程:如何优雅地关闭线程
数据类型隐式转换导致的阻塞
WebAPi实现多文件上传,并附带参数
from origin ‘null‘ has been blocked by
UE4 蓝图调用C++函数(附带项目工程)
Unity学习笔记(一)结构体的简单理解与应用
【Memory As a Programming Concept in C a
上一篇文章      下一篇文章      查看所有文章
加:2022-04-04 12:42:53  更:2022-04-04 12:43:55 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年10日历 -2024/10/29 4:23:08-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码