Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

将 Date 对象转换为 Unix 时间戳; 输出长度为 10 位或 13 位的时间戳 #23

Merged
merged 1 commit into from
Jul 30, 2024

Conversation

penn201500
Copy link
Contributor

Date 转换成 Unix 时间戳:

image

/ * 
 * @example
 * // 示例: 有效的 Date 对象,输出秒级时间戳
 * console.log(dateToTimestamp(new Date())) // 输出: Unix 时间戳(10位数字)
 *
 * @example
 * // 示例: 有效的 Date 对象,输出毫秒级时间戳
 * console.log(dateToTimestamp(new Date(), true)) // 输出: Unix 时间戳(13位数字)
 *
 * @example
 * // 示例: 无效的 Date 对象
 * console.log(dateToTimestamp(new Date("invalid"))) // 输出: null
 *
 * @example
 * // 示例: 显然无效的 Date 对象
 * console.log(dateToTimestamp(new Date('1000-00-00 00:00:00Z'))) // 输出: null
 */

@chenbimo
Copy link
Owner

感谢分享~

@chenbimo chenbimo merged commit 3c7f582 into chenbimo:main Jul 30, 2024
@penn201500 penn201500 deleted the DateToTs branch August 3, 2024 09:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants