How to Get Tomorrow\'s Time with a Specific Hour and Minute in Go?

Susan Sarandon
Release: 2024-11-05 06:57:01
Original
301 people have browsed it

How to Get Tomorrow's Time with a Specific Hour and Minute in Go?

Getting Time for the Next Day

Question:

How to write a more concise code to get an exact time for the following day (tomorrow) with specific hour and minute?

Answer:

Package time provides a better way to achieve this goal. It normalizes the values for month, day, hour, minute, second, and nanosecond during the conversion. Here's an efficient code snippet:

<code class="go">package main

import (
    "fmt"
    "time"
)

func main() {
    now := time.Now()
    fmt.Println(now.Round(0))
    yyyy, mm, dd := now.Date()
    tomorrow := time.Date(yyyy, mm, dd+1, 15, 0, 0, 0, now.Location())
    fmt.Println(tomorrow)
}</code>
Copy after login

This code is more efficient because it minimizes the number of calls to package time functions and methods. Benchmarks show that it is faster than other approaches.

The above is the detailed content of How to Get Tomorrow\'s Time with a Specific Hour and Minute in Go?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template