<?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/">
  <channel>
    <title>DEV Community: houtizong</title>
    <description>The latest articles on DEV Community by houtizong (@houtizong).</description>
    <link>https://dev.to/houtizong</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F886718%2Fab21a767-7095-4896-af46-6f1bbc0ace77.png</url>
      <title>DEV Community: houtizong</title>
      <link>https://dev.to/houtizong</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/houtizong"/>
    <language>en</language>
    <item>
      <title>go : Calculate the distance and format unit from the current time based on the timestamp</title>
      <dc:creator>houtizong</dc:creator>
      <pubDate>Thu, 07 Jul 2022 06:33:00 +0000</pubDate>
      <link>https://dev.to/houtizong/go-calculate-the-distance-and-format-unit-from-the-current-time-based-on-the-timestamp-ef2</link>
      <guid>https://dev.to/houtizong/go-calculate-the-distance-and-format-unit-from-the-current-time-based-on-the-timestamp-ef2</guid>
      <description>&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//根据时间戳计算与当前时间的间距及格式化单位
func FormatDate(in string) (out string) {
    timeUnix := time.Now().Unix() //当前时间戳

    inn, _ := strconv.ParseInt(in, 10, 64)
    outt := timeUnix - inn

    f := map[string]string{
        "1":        "秒",
        "60":       "分钟",
        "3600":     "小时",
        "86400":    "天",
        "604800":   "星期",
        "2592000":  "个月",
        "31536000": "年",
    }

    var keys []string
    for k := range f {
        keys = append(keys, k)
    }
    //sort.Strings(keys)
    //数字字符串 排序
    sort.Slice(keys, func(i, j int) bool {
        numA, _ := strconv.Atoi(keys[i])
        numB, _ := strconv.Atoi(keys[j])
        return numA &amp;lt; numB
    })

    for _, k := range keys {
        v2, _ := strconv.Atoi(k)
        cc := math.Floor(float64(int(outt) / int(v2)))
        if 0 != cc {
            out = strconv.FormatFloat(cc, 'f', -1, 64) + f[k] + "前"
        }
    }

    return
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For implementation details, visit &lt;a href="https://www.zongscan.com/demo333/398.html"&gt;my blog&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>go</category>
    </item>
  </channel>
</rss>
