{"id":782,"date":"2022-05-06T07:37:07","date_gmt":"2022-05-05T23:37:07","guid":{"rendered":"https:\/\/log.tanxiaodian.com\/?p=782"},"modified":"2022-05-06T07:37:08","modified_gmt":"2022-05-05T23:37:08","slug":"go-web%e6%9c%8d%e5%8a%a1%e6%a1%88%e4%be%8b%e4%bb%a5%e5%8f%8a%e6%97%b6%e9%97%b4%e5%a4%84%e7%90%86","status":"publish","type":"post","link":"https:\/\/log.tanxiaodian.com\/?p=782","title":{"rendered":"Go Web\u670d\u52a1\u6848\u4f8b\u4ee5\u53ca\u65f6\u95f4\u5904\u7406"},"content":{"rendered":"\n<p>\u6ce8\u610fgo\u7684\u65f6\u95f4\u683c\u5f0f\u5316\u5fc5\u987b\u6307\u5b9aformat\u7684\u6a21\u677f\u4e3a &#8220;2006-01-02 15:04:05&#8221; <\/p>\n\n\n\n<p>package main<br>import(<br>&#8220;fmt&#8221;<br>&#8220;net\/http&#8221;<br>&#8220;log&#8221;<br>&#8220;time&#8221;<br>&#8220;strconv&#8221;<br>)<\/p>\n\n\n\n<p>func timeStamp2DateTime(w http.ResponseWriter, r *http.Request) {<br>r.ParseForm()<br>nowTime := time.Unix(time.Now().Unix(), 0).Format(&#8220;2006-01-02 15:04:05&#8221;)<br>var tm_input = r.Form[&#8220;time&#8221;][0]<br>fmt.Println(nowTime + &#8220;\u8f93\u5165:&#8221; + tm_input)<br>tm,err := strconv.ParseInt(tm_input, 10, 64)<br>if err != nil {<br>fmt.Println(&#8220;can&#8217;t convert to init&#8221;)<br>}<\/p>\n\n\n\n<p>}<\/p>\n\n\n\n<p>func DateTime2TimeStamp(w http.ResponseWriter, r *http.Request) {<br>r.ParseForm()<br>var input_tm = r.Form[&#8220;date&#8221;][0] + &#8221; 00:00:00&#8243;<br>nowTime := time.Unix(time.Now().Unix(), 0).Format(&#8220;2006-01-02 15:04:05&#8221;)<br>fmt.Println(nowTime + &#8220;\u8f93\u5165&#8221; + input_tm)<br>times, _ := time.Parse(&#8220;2006-01-02 15:04:05&#8221;, input_tm)<br>timeUnix := times.Unix() &#8211; 3600 * 8<br>fmt.Fprintf(w, fmt.Sprintf(&#8220;\u65e5\u671f\u8f6c\u65f6\u95f4\u6233:%v&#8221;, timeUnix));<br>}<\/p>\n\n\n\n<p>func main(){<br>http.HandleFunc(&#8220;\/timestamp2date&#8221;, timeStamp2DateTime)<br>http.HandleFunc(&#8220;\/date2timestamp&#8221;, DateTime2TimeStamp)<br>err := http.ListenAndServe(&#8220;:9090&#8221;, nil)<br>if err != nil {<br>log.Fatal(&#8220;ListenAndServe:&#8221;, err)<br>}<br>}<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6ce8\u610fgo\u7684\u65f6\u95f4\u683c\u5f0f\u5316\u5fc5\u987b\u6307\u5b9aformat\u7684\u6a21\u677f\u4e3a &#8230;<\/p>\n<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"https:\/\/log.tanxiaodian.com\/?p=782\">Continue reading<span class=\"screen-reader-text\">Go Web\u670d\u52a1\u6848\u4f8b\u4ee5\u53ca\u65f6\u95f4\u5904\u7406<\/span><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[137],"tags":[142],"_links":{"self":[{"href":"https:\/\/log.tanxiaodian.com\/index.php?rest_route=\/wp\/v2\/posts\/782"}],"collection":[{"href":"https:\/\/log.tanxiaodian.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/log.tanxiaodian.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/log.tanxiaodian.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/log.tanxiaodian.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=782"}],"version-history":[{"count":1,"href":"https:\/\/log.tanxiaodian.com\/index.php?rest_route=\/wp\/v2\/posts\/782\/revisions"}],"predecessor-version":[{"id":783,"href":"https:\/\/log.tanxiaodian.com\/index.php?rest_route=\/wp\/v2\/posts\/782\/revisions\/783"}],"wp:attachment":[{"href":"https:\/\/log.tanxiaodian.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=782"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/log.tanxiaodian.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=782"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/log.tanxiaodian.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=782"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}