网站公告

本次更新:新公告样式

详细教程:vitepress.yiov.top

QQ 频道:******(无效二维码)

Skip to content

getCountdown时间倒计时

更新: 1970/1/1 字数: 0 字 时长: 0 分钟

说明

getCountdown 是一个实现倒计时功能的函数,可以实时显示到目标日期剩余的年、月、周、天、小时、分钟、秒。

参数说明

参数类型描述
targetDateDate目标日期,可以是 JavaScript Date 对象
unitString (可选)时间单位,可选值包括:yearmonthweekdayhourminutesecond

返回值

  • 如果没有提供 unit 参数,函数返回一个包含以下属性的对象:
    • years: 年数
    • months: 月数
    • weeks: 周数
    • days: 天数
    • hours: 小时数
    • minutes: 分钟数
    • seconds: 秒数
  • 如果提供了 unit 参数,函数返回一个数字,表示到目标日期在该单位下的剩余时间。

示例

js
import { getCountdown } from 'uviewos';

// 获取到目标日期的倒计时对象
const targetDate = new Date('2024-12-31');

const countdown = getCountdown(targetDate);
console.log(countdown);
// 输出类似于:
// {
//   years: 0,
//   months: 3,
//   weeks: 1,
//   days: 24,
//   hours: 0,
//   minutes: 0,
//   seconds: 0
// }

// 获取到目标日期在特定单位下的剩余时间
const daysRemaining = getCountdown(targetDate, '天');
console.log(daysRemaining);
// 输出: 112

Released under the MIT License.

本站访客数 人次 本站总访问量