golang time模块

var json = import("json");
var fmt = import("fmt");
var ioutil = import("io/ioutil")
var time = import('time')

 

 

# 字符串时间转为时间格式

time.Parse("2006-01-02", “2018-11-11”)

 

# 时间格式化成字符串

now_time = time.Now()

now_time .Format("2006-01-02 15:04:05")

 

#     func Date_time(start_time,end_time){
#         fmt = import("fmt")
#         time = import("time")
#         # var t = time.Now()
#         var dates = []
        
#         var res= DURATION(24,0,0)  
#         datetime = start_time
#         for{
            
#             if DATETIME_AFTER(datetime,end_time){
            
#                 break
#             }else{
                
#                 if datetime.Weekday().String() in ["Monday","Tuesday","Wednesday","Thursday","Friday"] {
#                     dates = dates + [datetime]     
#                 }
#                 datetime = DATETIME_ADD_DURATION(datetime,res)
            
#             }
            
#         }
#         return dates
    
# }

#     res = Date_time(DATE(2018, 10, 15), DATE(2018, 10, 31))

 

# 获得每月1号和月末

 

 

time.Now()

now_time = time.Now()
old_time = now_time.Add(-24 * time.Hour)
# 本月第一天
firstDay = time.Date(old_time.Year(), old_time.Month(), 1, 00, 00,00, 0, old_time.Location())
firstDay_end = time.Date(old_time.Year(), old_time.Month(), 1, 23, 59,59, 0, old_time.Location())
# 本月最后一天23:59:59
next_month_first = time.Date(old_time.Year(), old_time.Month()+1, 1, 00, 00,00, 0, old_time.Location())
minus_time = DURATION(0,0,-1)

    
lastDay = DATETIME_ADD_DURATION(next_month_first,minus_time)

你可能感兴趣的:(golang time模块)