donglvchu9143 2015-07-02 05:00
浏览 39
已采纳

同时使用新变量和赋值变量

wd := new(time.Weekday)
fmt.Println(wd.String())

The above two lines return Sunday (weekdays start with a 0)

Is it possible for me to assign a value along with new ? Other method i tried is

var wd time.Weekday
wd = 3

this one returns Wednesday

  • 写回答

2条回答 默认 最新

  • dongtuan1594 2015-07-02 05:38
    关注

    time.Weekday is an int so you can assign it as such (or use the defined constants as Adam suggested). Can I ask why you need to use new in this situation?

    package main
    
    import (
        "fmt"
        "time"
    )
    
    func main() {
        var wd time.Weekday = 3
        fmt.Println(wd)
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何解决ldsc的这条报错/index error
  • ¥15 VS2022+WDK驱动开发环境
  • ¥30 关于#java#的问题,请各位专家解答!
  • ¥30 vue+element根据数据循环生成多个table,如何实现最后一列 平均分合并
  • ¥20 pcf8563时钟芯片不启振
  • ¥20 pip2.40更新pip2.43时报错
  • ¥15 换yum源但仍然用不了httpd
  • ¥50 C# 使用DEVMOD设置打印机首选项
  • ¥15 麒麟V10 arm安装gdal
  • ¥20 OPENVPN连接问题