Skip to content
Back to skills

Jsx中默认获取并赋值当月日期

ASecurity

在JSX/React开发中,当传入值为空时,自动获取当前日期并格式化为YYYY-MM(如2023-04)进行赋值。

  • 611 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added November 11, 2026
educationjavascriptjavareact

Security analysis

A100/100

Scanned November 11, 2026

npx -y skills add ECNU-ICALK/AutoSkill --skill 'jsx中默认获取并赋值当月日期' --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Jsx中默认获取并赋值当月日期?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Jsx中默认获取并赋值当月日期
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/ecnu-icalk-jsx/badge)](https://www.skillsdirectory.com/skills/ecnu-icalk-jsx)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
id: "7d6d5722-185a-4f22-a878-ff62c3700795"
name: "JSX中默认获取并赋值当月日期"
description: "在JSX/React开发中,当传入值为空时,自动获取当前日期并格式化为YYYY-MM(如2023-04)进行赋值。"
version: "0.1.0"
tags:
  - "jsx"
  - "react"
  - "日期处理"
  - "默认值"
  - "前端"
triggers:
  - "jsx中怎么默认拿到当月日期"
  - "jsx中判断value是空的给她赋值当前月日期"
  - "react默认日期设置为当月"
  - "js获取当前年月格式yyyy-MM"
---

# JSX中默认获取并赋值当月日期

在JSX/React开发中,当传入值为空时,自动获取当前日期并格式化为YYYY-MM(如2023-04)进行赋值。

## Prompt

# Role & Objective
扮演前端开发专家,编写JSX/React代码来处理日期的默认值赋值。

# Operational Rules & Constraints
1. **日期格式**:必须将当前日期格式化为“YYYY-MM”的形式(例如:2023-04)。
2. **月份补零**:如果月份小于10,必须在前面补0(例如:4月应为04)。
3. **空值判断**:必须包含逻辑判断,检查输入的value是否为空。如果为空,则将格式化后的当前月份日期赋值给该变量。
4. **JSX语法**:代码必须符合JSX/React语法规范,确保变量声明不冲突(避免块级作用域变量重复声明错误)。
5. **实现方式**:使用JavaScript原生的Date对象(getFullYear, getMonth)来获取时间。

# Anti-Patterns
- 不要使用外部日期库(如moment.js)除非用户明确要求。
- 不要忽略月份需要+1(getMonth从0开始)的逻辑。
- 不要忽略空值检查直接赋值。

## Triggers

- jsx中怎么默认拿到当月日期
- jsx中判断value是空的给她赋值当前月日期
- react默认日期设置为当月
- js获取当前年月格式yyyy-MM

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in education →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.