![]() In the main.go file, add a main function that will get the current time and print it out: Once you have your project directory created, open a main.go file using nano, or your preferred editor: Make the projects directory and navigate to it:įrom the projects directory, run mkdir to create a datetime directory and then use cd to navigate to it: In this tutorial, you’ll use a directory named projects. This directory can be created anywhere you’d like on your computer, but many developers tend to have a directory for their projects. To begin creating a program to explore the time package, you’ll need to create a directory for the files. In addition to a time and date, it can also hold information about the time zone the represented date and time are in. The time package in Go’s standard library provides a variety of date- and time-related functions, and can be used to represent a specific point in time using the time.Time type. ![]() In this section, you will get the current time using Go’s time package. To set this up, follow the How To Install Go tutorial for your operating system. You will also translate the date and time values between two time zones, as well as add or subtract time values to determine the interval between two times. Next, you will interpret a string to extract the date and time information. In this tutorial, you will create a Go program to get the current local time of your computer, then print it to the screen in a format that is easier for people to read. Therefore, retrieving the current time, manipulating time values to extract information from them, and displaying them to users in an easy-to-understand format are essential properties of an application. For example, keeping track of when a car needs service and letting the owner know, keeping track of changes in a database to create an audit log, or just comparing one time to another to determine how long a process took. Date and time values show up everywhere in modern software. Software is designed to make it easier to get work done, and for many people, that includes interacting with dates and times. If you make the change, you’ll see a warning about the dire effects this may have on your system in the future.The author selected the Diversity in Tech Fund to receive a donation as part of the Write for DOnations program. It’s possible to have your real-time clock set to your local time zone time instead of to UTC-possible, but inadvisable. If you have internet access, as soon as you restore the time synchronization service the time is retrieved and all of the details are correctly reset. We’re also informed that the system clock is not being synchronized and the NTP service is inactive. Also, note the computer is using a false UTC time. We’ll then check that the changes have taken place, using timedatectl. We’re going to set the time and date with this command: timedatectl set-time " 10:30:00" dates are in year-month-day order YYY-MM-DD, and time is in hours-minutes-seconds order HH:MM:SS. You can set the time, the date, or both using the timedatectl set-time operator. That’s why it is vital that your computer knows which timezone it is, what UTC time is, how many seconds have passed since the Unix epoch, and whether daylight savings time is in effect. Or, more accurately, the conversion is performed by the time and date libraries that the application is linked to. The conversion from UTC to local time is done by the application, not the system clock.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |