# 获取当前时间

> 获取真实当前时间，防止新闻写作时的时间误判

- **Type:** Skill
- **Install:** `agentstack add skill-hhhh124hhhh-skillmate-get-current-time`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [hhhh124hhhh](https://agentstack.voostack.com/s/hhhh124hhhh)
- **Installs:** 0
- **Category:** [Agent Skills](https://agentstack.voostack.com/c/agent-skills)
- **Latest version:** 0.1.0
- **License:** Apache-2.0
- **Upstream author:** [hhhh124hhhh](https://github.com/hhhh124hhhh)
- **Source:** https://github.com/hhhh124hhhh/SkillMate/tree/main/resources/skills/get_current_time

## Install

```sh
agentstack add skill-hhhh124hhhh-skillmate-get-current-time
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

# 获取当前时间工具

在撰写新闻类文章时，快速获取当前真实日期和时间，防止将真实新闻误判为"虚构内容"。

## 📌 核心功能

### 1. 获取当前时间
- 获取完整的当前日期和时间
- 返回多种格式的日期字符串
- 提供时间戳信息

### 2. 文章格式化时间
- 生成新闻文章常用的日期格式
- 包括："今天"、"昨天"、"本周"、"本月"等
- 适用于不同场景的时间表达

### 3. 日期差异检查
- 检查目标日期与今天的差异
- 判断日期是过去、今天还是未来
- 生成人类可读的时间差描述

## 🚀 使用方式

### 方式一：通过Python脚本

```python
from get_current_time import handler

# 1. 获取当前时间
result = handler({"action": "get_current"})
print(result)
# 输出: {
#   "current_date": "2026年01月15日",
#   "current_time": "14:30:25",
#   "year": 2026,
#   "month": 1,
#   "day": 15,
#   "full_datetime": "2026年01月15日 14:30:25",
#   ...
# }

# 2. 获取文章常用格式
result = handler({"action": "format_for_article"})
print(result)
# 输出: {
#   "今天": "2026年01月15日",
#   "今天上午": "2026年01月15日上午",
#   "昨天": "2026年01月14日",
#   "本周": "2026年01月第3周",
#   "本月": "2026年01月",
#   "今年": "2026年",
#   "相对时间_今天": "今天",
#   "相对时间_昨天": "昨天",
#   ...
# }

# 3. 检查日期差异
result = handler({
    "action": "check_date",
    "target_date": "2026-01-20"
})
print(result)
# 输出: {
#   "target_date": "2026年01月20日",
#   "today": "2026年01月15日",
#   "days_difference": 5,
#   "is_future": true,
#   "is_past": false,
#   "is_today": false,
#   "human_readable": "5天后"
# }
```

### 方式二：通过命令行

```bash
# 获取当前时间
python get_current_time.py --action get_current

# 获取文章格式
python get_current_time.py --action format_for_article

# 检查日期差异
python get_current_time.py --action check_date --target-date "2026-01-20"
```

### 方式三：通过Skill工具

在Claude Code中使用Skill工具调用：

```python
from skill import handler

result = handler({
    "skill": "get_current_time",
    "args": {
        "action": "get_current"
    }
})
```

## 🎯 使用场景

### 场景1：撰写突发新闻

在写新闻类文章时，快速获取当前时间：

```python
from get_current_time import handler

time_info = handler({"action": "format_for_article"})

# 文章开头
print(f"今天{time_info['今天上午']}，阿里云栖小镇...")
```

### 场景2：验证事件时间

检查某个事件是过去还是未来：

```python
from get_current_time import handler

# 检查发布会时间
result = handler({
    "action": "check_date",
    "target_date": "2026-01-15"
})

if result["is_today"]:
    print("就是今天！")
elif result["is_future"]:
    print(f"这是未来事件，发生在{result['human_readable']}")
else:
    print(f"这是过去事件，发生在{result['human_readable']}")
```

### 场景3：避免时间误判

在撰写"今天发生"的新闻时，先验证：

```python
from get_current_time import handler

# 检查文章中的日期
dates_to_check = [
    "2026-01-15",  # 发布会
    "2026-02-01",  # 功能上线
    "2025-12-10",  # 公测23天
]

for date_str in dates_to_check:
    result = handler({
        "action": "check_date",
        "target_date": date_str
    })
    print(f"{date_str}: {result['human_readable']}")

# 输出:
# 2026-01-15: 就是今天
# 2026-02-01: 17天后
# 2025-12-10: 36天前
```

## 💡 最佳实践

### 1. 新闻写作前先检查时间

在写任何包含"今天"、"刚才"等时间词的新闻前：

```python
from get_current_time import handler

# 获取当前时间
current = handler({"action": "get_current"})
print(f"当前时间: {current['full_datetime']}")

# 检查事件时间
event = handler({
    "action": "check_date",
    "target_date": "2026-01-15"
})
print(f"事件时间: {event['target_date']}")
print(f"时间差异: {event['human_readable']}")
```

### 2. 文章中标注时间来源

```markdown
**正确写法**:
> 今天（2026年1月15日）上午，阿里云栖小镇...

**错误写法**:
> 今天上午，阿里云栖小镇...（没有具体日期）
```

### 3. 验证数据时效性

在引用数据时，检查其时效性：

```python
from get_current_time import handler

# 检查数据发布时间
data_result = handler({
    "action": "check_date",
    "target_date": "2025-09-30"  # QuestMobile三季度数据
})

print(f"数据发布于: {data_result['human_readable']}")

if abs(data_result['days_difference']) > 180:
    print("⚠️ 警告: 数据可能已过时（超过6个月）")
```

### 4. 使用相对时间

根据时间差选择合适的表达：

```python
from get_current_time import handler

event = handler({
    "action": "check_date",
    "target_date": "2026-01-10"
})

days = abs(event['days_difference'])

if days == 0:
    expression = "今天"
elif days == 1:
    expression = "昨天"
elif days < 7:
    expression = f"{days}天前"
elif days < 30:
    expression = f"{days//7}周前"
else:
    expression = event['target_date']

print(f"事件发生于{expression}")
```

## 📝 返回数据说明

### get_current 返回字段

| 字段 | 类型 | 说明 | 示例 |
|------|------|------|------|
| current_date | string | 当前日期 | "2026年01月15日" |
| current_time | string | 当前时间 | "14:30:25" |
| year | int | 年份 | 2026 |
| month | int | 月份 | 1 |
| day | int | 日期 | 15 |
| weekday | string | 星期几（英文） | "Wednesday" |
| full_datetime | string | 完整日期时间 | "2026年01月15日 14:30:25" |
| timestamp | float | Unix时间戳 | 1705319425.123 |
| iso_format | string | ISO格式 | "2026-01-15T14:30:25" |

### format_for_article 返回字段

| 字段 | 类型 | 说明 | 示例 |
|------|------|------|------|
| 今天 | string | 今天日期 | "2026年01月15日" |
| 今天上午 | string | 今天上午 | "2026年01月15日上午" |
| 今天下午 | string | 今天下午 | "2026年01月15日下午" |
| 昨天 | string | 昨天日期 | "2026年01月14日" |
| 本周 | string | 本周 | "2026年01月第3周" |
| 本月 | string | 本月 | "2026年01月" |
| 今年 | string | 今年 | "2026年" |
| 相对时间_今天 | string | "今天" | "今天" |
| 相对时间_昨天 | string | "昨天" | "昨天" |
| 相对时间_本周 | string | "本周" | "本周" |
| 相对时间_本月 | string | "本月" | "本月" |

### check_date 返回字段

| 字段 | 类型 | 说明 | 示例 |
|------|------|------|------|
| target_date | string | 目标日期 | "2026年01月20日" |
| today | string | 今天日期 | "2026年01月15日" |
| days_difference | int | 天数差 | 5 |
| is_future | bool | 是否未来 | true |
| is_past | bool | 是否过去 | false |
| is_today | bool | 是否今天 | false |
| human_readable | string | 人类可读差异 | "5天后" |

## ⚠️ 注意事项

### 1. 时区问题
脚本使用系统本地时区，确保你的系统时区设置正确。

### 2. 日期格式
支持的日期输入格式：
- "2026-01-15" (推荐)
- "2026年01月15日"
- "2026/01/15"

### 3. 跨天判断
"今天"是基于0:00-24:00的完整自然日，不是24小时周期。

### 4. 时间精度
时间精度到秒，对于大多数新闻场景已足够。

## 🔧 故障排除

### 问题1：时间不准确

**原因**：系统时区设置错误

**解决**：
```bash
# Windows
# 控制面板 → 时间和语言 → 设置时区

# Linux/Mac
sudo timedatectl set-timezone Asia/Shanghai
```

### 问题2：日期解析失败

**原因**：日期格式不支持

**解决**：使用推荐的 "YYYY-MM-DD" 格式

### 问题3：编码问题（Windows）

**原因**：Windows控制台编码问题

**解决**：脚本已自动处理Windows编码问题

## 📚 相关工具

- `datetime_check.py`: 批量检查文章中的日期
- `article_date_validator.py`: 验证整篇文章的日期一致性

## 💻 技术细节

- 语言：Python 3.7+
- 依赖：仅使用标准库（datetime, json, sys）
- 兼容性：Windows, Linux, macOS
- 性能：毫秒级响应

---

**使用建议**：每次撰写新闻类文章前，先运行此脚本获取当前时间，避免时间误判！

## Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [hhhh124hhhh](https://github.com/hhhh124hhhh)
- **Source:** [hhhh124hhhh/SkillMate](https://github.com/hhhh124hhhh/SkillMate)
- **License:** Apache-2.0

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** no
- **Filesystem access:** no
- **Shell / process execution:** no
- **Environment & secrets:** no
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/skill-hhhh124hhhh-skillmate-get-current-time
- Seller: https://agentstack.voostack.com/s/hhhh124hhhh
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
