<?xml version="1.0" encoding="utf-8"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"><channel><title>MagicLen</title><link>https://magiclen.org/cn/tag/date-differencer/</link><description>多元化原创文章，内容包罗万象，有编程语言、网站应用、软件介绍、硬件介绍、操作系统、旅行游记、专题采访、益智问题、文学创作，以及作者们的知识分享和作品分享。</description><language>zh-CN</language><lastBuildDate>Sun, 22 Nov 2026 18:40:46 +0800</lastBuildDate><atom:link href="https://magiclen.org/cn/tag/date-differencer/feed/" rel="self" type="application/rss+xml"/><sy:updatePeriod>hourly</sy:updatePeriod><sy:updateFrequency>8</sy:updateFrequency><sy:updateBase>1970-01-01T00:00+00:00</sy:updateBase><item><title>如何写程序计算时间和日期的差距？</title><link>https://magiclen.org/cn/date-differencer/</link><description><![CDATA[<img src="https://magiclen.org/wp-content/uploads/2023/01/arrow-2085192_1920-220x162.jpg" srcset="https://magiclen.org/wp-content/uploads/2023/01/arrow-2085192_1920-220x162.jpg 1x, https://magiclen.org/wp-content/uploads/2023/01/arrow-2085192_1920-440x324.jpg 2x, https://magiclen.org/wp-content/uploads/2023/01/arrow-2085192_1920-660x486.jpg 3x" alt>
有时候我们会需要写程序去计算两个时间点的差距，以求得年龄、经过了多少的时间，或是否还在某个期限之内等等的信息。日(day)与时、分、秒的差距很好算，因为它们是固定的时间（不考虑闰秒）。但年、月就不一样了，一个月可能有 28 至 31 天，一年可能有 365 或 366 天，我们无法直接将两个时间点（的时间戳记）相减之后去除上一个固定的单位（例如拿相差的秒数去除以 2592000 秒）来算出隔了多少...]]></description><category>研究分享</category><category>Rust</category><category>算法</category><category>JavaScript</category><category>JavaScript</category><category>Rust</category><category>TypeScript</category><category>烂 Code</category><category>date-differencer</category><guid>https://magiclen.org/cn/date-differencer</guid><pubDate>Tue, 24 Jan 2023 12:00:00 +0800</pubDate><dc:creator>Magic Len</dc:creator></item></channel></rss>