小编cat*_*ter的帖子

如何在字符串中找到给定日期的工作日?

我的应用程序中有一个函数将字符串中的日期保存到数据库中,但它无法保存该日期的那一天.我试过一个简短的代码.假设我们在字符串中有一个日期.

码:

package main

import (
    "fmt"
    "strconv"
    "strings"
    "time"
)   

func main() {
    p := fmt.Println
    date := "01-25-2019"
    arrayDate := strings.Split(date, "-")
    fmt.Println(arrayDate)
    month, _ := strconv.Atoi(arrayDate[0])
    dateInt, _ := strconv.Atoi(arrayDate[1])
    year, _ := strconv.Atoi(arrayDate[2])
    then := time.Date(
        year, time.Month(month), dateInt, 0, 0, 0, 0, time.UTC)
    p(then)

    p(then.Weekday())

}
Run Code Online (Sandbox Code Playgroud)

有没有更有效的方法来做到这一点?

游乐场链接

string time date go weekday

1
推荐指数
1
解决办法
215
查看次数

如何以json格式读取数据?

我有一个函数,我必须将数据发布到json格式的URL.当我发送数据时,它将在json中给出响应.但它会告诉我像: -

代码给出的输出

&{200 OK 200 HTTP/1.1 1 1 
map[Content-Type:[application/json] X-Request-Id:[CgiFzq669pAYzRABGBAiCQiRtaznvJffAg] 
Keep-Alive:[timeout=60] 
Vary:[Accept-Encoding] 
X-Content-Type-Options:[nosniff] 
X-Download-Options:[noopen] 
X-Permitted-Cross-Domain-Policies:[none] 
Strict-Transport-Security:[max-age=631152000] 
X-Frame-Options:[DENY] 
X-Xss-Protection:[1; mode=block] 
Date:[Tue, 11 Dec 2018 09:35:22 GMT] 
Access-Control-Allow-Headers:[Content-Type, Authorization, Accept] 
Access-Control-Allow-Origin:[*] 
Access-Control-Expose-Headers:[Link]] 0xc420442080 -1 [] false true map[] 0xc42023e100 0xc4200e0d10}
Run Code Online (Sandbox Code Playgroud)

代码是: -

func Token(c *gin.Context) {
   code := c.Query("code")
   responseToken :=TokenResponse{}
   token := models.PostToken{
     ClientID:     "appllication Id",
     ClientSecret: "applicationSecreteId",
     Code:         "code",
     RedirectUri:  c.Request.Host + c.Request.URL.RequestURI(),
   }
   bindData, err := json.Marshal(token)
   if err != nil {
     panic(err)
   }
   var jsonStr = []byte(string(bindData)) …
Run Code Online (Sandbox Code Playgroud)

json go

-2
推荐指数
1
解决办法
79
查看次数

标签 统计

go ×2

date ×1

json ×1

string ×1

time ×1

weekday ×1