I want to have a struct like this:
type Person struct {
Name string
DateJoined time
}
But this struct will not compile, because there is no type time
, isn't it?
Should I alternatively use a string
and insert the time / date information there?
The operating system measures two types of time “Wall clock” time and “Monotonic” time. Wall clock time is used to tell time whereas monotonic clock time is used to measure time. Go time package provides functionalities to measure and manipulate both clocks.
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 addition to a time and date, it can also hold information about the time zone the represented date and time are in.
time
isn't a type. time.Time
is. See the package docs for the types: http://golang.org/pkg/time/
import time
type Person struct {
Name string
DateJoined time.Time
}
you need to import time package and of course you use time.Time btw, it returned error when I defined my own type as below with similar reason to you. And, someone helped me to do cast (ex. mytime(time.Now()).
type mytime time.Time
You can make your own package and import always so that all your own type in your convenience
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With