DateTime? Nullable当我使用DateTime时?作为Nullable类型“ToString(”dd MMMMyyyy“+”(HH:mm tt)“)”出现错误。
答案 0 :(得分:2)
你必须使用这样的东西。我已根据Colin
的建议添加了空检查// My SignupModel
type SignupModel struct {
ID string `json:"id"`
Username string `json:"username"`
FbToken string `json:"fbtoken"`
Email string `json:"email"`
Firstname string `json:"firstname"`
Lastname string `json:"lastname"`
Picture string `json:"picture"`
}
// This is the condition I'm using inside my route (I know it's terrible)
if signup.ID != "" && signup.Username != "" && signup.FbToken == "" && signup.Email == "" && signup.Firstname == "" && signup.Lastname == "" && signup.Picture == "" {
json.NewEncoder(w).Encode(signup)
} else {
statusResponse := StatusResponse{Status: "Something went wrong", StatusCode: 401}
json.NewEncoder(w).Encode(statusResponse)
}
if(dateVariable.HasValue)
string dateString = dateVariable.Value.ToString("dd MMMMyyyy " + "(HH:mm tt)");
是一个generc,它包装了对象。您必须通过Nullable<T>
属性访问它。