对于时间的一些处理

1. 获取当前时间的后一天
getDate() {
   
  // 获取当前时间
  let date = new Date();
  // 当前时间转换为时间戳(13位,不足13位要*1000)
  date = date.getTime();
  // 在当前时间戳数据基础上加上一天的时间戳数据(我之前在网上搜了一天的时间戳是86400,怎么转换都是当天,后面才发现没有*1000,*1000是精确到毫秒)
  date = date  + 86400000;
  // 将操作后的时间戳转换为系统时间格式		
  let dateInfo = new Date(date);

  // 将系统时间格式转换为自定义时间格式
  let year = dateInfo.getFullYear();
  let month = dateInfo.getMonth() + 1;
  let day = dateInfo.getDate();
	
  month = month > 9 ? month : '0' + month;;
  day = day > 9 ? day : '0' + day;
  return `${
     year}-${
     month}-${
     day}`;
},
2. 时间转换处理成想要的数据(自定义时分秒,默认开始)
// 日期时间处理为00:00:00
function dateToZeroTime(dateString?: string | Date, timeString = '00:00:00'): number {
   
  const newDate = dateString ? new Date(dateString) : new Date();
  const year = newDate.getFullYear();
  const month = newDate.getMonth() + 1;
  const date = newDate.getDate();

  return new Date(`${
     year}-${
     month}-${
     date} ${
     timeString}`).getTime();
}
3. 时间转换处理成想要的数据(自定义时分秒,默认结束)
// 日期时间处理为23:59:59
function dateToFinalTime(dateString?: string | Date): number {
   
  const newDate = dateString ? new Date(dateString) : new Date();
  const year = newDate.getFullYear()
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值