package main
import (
"fmt"
"time"
)
type Unix struct {
Val int64
}
func main() {
var u1 = Unix{}
var u2 = Unix{}
u1.Val = 1562586024 // 2019-07-08 19:40:24
u2.Val = time.Now().Unix()
fmt.Println(u1.IsTody())
fmt.Println(u1.IsSameDay(u2))
if !u1.IsSameDay(u2) {
fmt.Println("不相同")
}else{
fmt.Println("相同")
}
if !u1.IsTody() {
fmt.Println("不相同")
}else{
fmt.Println("相同")
}
}
func (u *Unix) IsTody() bool {
tm := time.Unix(u.Val, 0)
tmToday := time.Now()
if tmToday.Day() == tm.Day() {
return true
}
return false
}
/**
* 二个时间戳是否同一天
* @return true 是 false 不是今天
*/
func (u *Unix) IsSameDay(another *Unix) bool {
tm := time.Unix(u.Val, 0)
tmAnother := time.Unix(another.Val, 0)
if tmAnother.Day() == tm.Day() {
return true
}
return false
}