js怎样获取本季度28日下午16:00:00的时间戳?

js怎样获取本季度28日下午16:00:00的时间戳?

阅读 3.8k
6 个回答

请问季度28日存在吗, 我还想知道本世纪28日是哪一天.

从来没有了到还需要科普季度的知识

来自百度百科

人们俗称的“季度”,就是把一年平均分成四份,按照春、夏、秋、冬的顺序
一年可以分为四个季度,每个季度历时3个月。
第一季度:1月-3月
第二季度:4月-6月
第三季度:7月-9月
第四季度:10月-12月
而实际上严格的划分应该为:(按照中国的纬度)
第一季度:3-5月(春季)
第二季度:6-8月(夏季)
第三季度:9-11月(秋季)
第四季度:12-2月(冬季)

问题应改为 求当前季度最后一个月28日16点时间戳

var currentDate = new Date();
var currentSeasonLastMonth = Math.ceil((currentDate.getMonth() + 1)/3)*3;
var currentSeasonLast28 = new Date(currentDate.getFullYear(), currentSeasonLastMonth-1, 28, 16, 0);
console.log(currentSeasonLast28.valueOf());  //打印出当季最后一个月28日16点的时间戳
moment().startOf('quarter').add({days:28,hours:16})

有现成的工具为啥不用呢

<script>
    var now = new Date;
    var nowMonth = now.getMonth() + 1; 
    if(nowMonth>=1 && nowMonth<=3){
        now.setMonth(2);  //这个地方应该是3-1=2
    }else if(nowMonth>=4 && nowMonth<=6){
        now.setMonth(5);
    }else if(nowMonth>=7 && nowMonth<=9){
        now.setMonth(8);
    }else if(nowMonth>=10 && nowMonth<=12){
        now.setMonth(11);
    }
    now.setDate(28);
    now.setHours(16);
    now.setMinutes( 0, 0, 0 );
    console.log("当前时间", now, "时间戳", now.getTime())
</script>

突出优秀 季度知识学到了

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题