Skip to content

时间 / 条件函数

时间

函数返回说明
now()Long当前时间戳(毫秒)
date()String当前日期 "yyyy-MM-dd"
time()String当前时间 "HH:mm:ss"
datetime()String完整时间 "yyyy-MM-dd HH:mm:ss"
hour()Integer当前小时(0–23)
minute()Integer当前分钟(0–59)
dayofweek()Integer星期几(1=周一, 7=周日,ISO 标准)
dayofmonth()Integer当月第几天(1–31)
month()Integer当前月份(1–12)
year()Integer当前年份
yaml
# 时段判断
是周末 = dayofweek() >= 6          # 周六、周日
是工作日 = dayofweek() <= 5
是夜晚 = hour() >= 20 || hour() < 6

# 时间戳
过去毫秒 = now() - 上次时间

# 字符串形式
当前日期 = date()                  # "2026-04-17"
完整时间 = datetime()              # "2026-04-17 14:30:45"

没有 second()

IM 不提供 second() 函数。要取秒数,可解析 time()

yaml
秒数 = split(time(), ":", 2)   # "45"

dayofweek 对照表

返回值星期
1周一
2周二
3周三
4周四
5周五
6周六
7周日

条件 / 空值

函数参数返回说明
clamp(value, min, max)Number×3Number限制在范围内(详见 数学函数
between(value, min, max)Number×3Boolean是否在 [min, max] 范围内
coalesce(a, b, ...)Any...Any返回第一个非 null / 非 0 的值
ifnull(value, default)Any×2Any值为 null 时返回默认值
typeof(value)AnyString返回类型名

typeof 返回值

返回类型
"null"null
"boolean"布尔
"number"数字
"string"字符串
"list"列表
"item"物品 ItemStack
"map"映射
"object"其他对象
yaml
# 取名称,没有就用默认值
名称 = ifnull(@input.name, "未知物品")

# 取第一个非空的
显示名 = coalesce(nbt_displayName, lore_firstLine, material_name)

# 类型判断
if typeof(数据) == "list" {
  大小 = list_size(数据)
}
if typeof(@input) == "item" {
  // 槽位有物品
}

何时用 ifnull vs coalesce

场景推荐
一个值 + 一个默认ifnull(值, 默认)
多个候选值,取第一个有效的coalesce(a, b, c, ...)
数值范围夹断clamp(v, min, max)
区间判断返回布尔between(v, min, max)

TQ Minecraft Server Plugin Docs