我想设置包含新当前日期和时间00:00:00的字符串.我编写了以下代码,但时间设置为12:00:00
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
String today1 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").
format(calendar.getTime())
Run Code Online (Sandbox Code Playgroud)
我很想知道为什么代码不起作用,或者,另一种方法是设置时间 00:00:00
我想从控制台获取文件路径并检查该文件是否为 vm 文件。我写了这段代码:
func main() {
reader := bufio.NewReader(os.Stdin)
fmt.Println("Enter the path of the vm file:")
path, _ := reader.ReadString('\n')
if filepath.Ext(path) != ".vm" {
fmt.Println("Error! file must be vm file")
}
Run Code Online (Sandbox Code Playgroud)
但它不起作用。我刚开始学习 Go 所以如果这是一个基本错误,请接受我的道歉。