本文整理汇总了Golang中Time.Time.Month方法的典型用法代码示例。如果您正苦于以下问题:Golang Time.Month方法的具体用法?Golang Time.Month怎么用?Golang Time.Month使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Time.Time
的用法示例。
在下文中一共展示了Time.Month方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: FmtDateLong
// FmtDateLong returns the long date representation of 't' for 'vi_VN'
func (vi *vi_VN) FmtDateLong(t time.Time) string {
b := make([]byte, 0, 32)
b = append(b, []byte{0x4e, 0x67, 0xc3, 0xa0, 0x79}...)
b = append(b, []byte{0x20}...)
if t.Day() < 10 {
b = append(b, '0')
}
b = strconv.AppendInt(b, int64(t.Day()), 10)
b = append(b, []byte{0x20, 0x74, 0x68, 0xc3, 0xa1, 0x6e, 0x67}...)
b = append(b, []byte{0x20}...)
if t.Month() < 10 {
b = append(b, '0')
}
b = strconv.AppendInt(b, int64(t.Month()), 10)
b = append(b, []byte{0x20, 0x6e, 0xc4, 0x83, 0x6d}...)
b = append(b, []byte{0x20}...)
b = strconv.AppendInt(b, int64(t.Year()), 10)
return string(b)
}
示例2: yearForMonth
func yearForMonth(mo time.Month, now *time.Time) int {
year := now.Year()
if mo+6 <= now.Month() {
year += 1
}
return year
}
示例3: IsActiveAt
// Returns wheter the Timing is active at the specified time
func (rit *RITiming) IsActiveAt(t time.Time) bool {
// check for years
if len(rit.Years) > 0 && !rit.Years.Contains(t.Year()) {
return false
}
// check for months
if len(rit.Months) > 0 && !rit.Months.Contains(t.Month()) {
return false
}
// check for month days
if len(rit.MonthDays) > 0 && !rit.MonthDays.Contains(t.Day()) {
return false
}
// check for weekdays
if len(rit.WeekDays) > 0 && !rit.WeekDays.Contains(t.Weekday()) {
return false
}
//log.Print("Time: ", t)
//log.Print("Left Margin: ", rit.getLeftMargin(t))
// check for start hour
if t.Before(rit.getLeftMargin(t)) {
return false
}
//log.Print("Right Margin: ", rit.getRightMargin(t))
// check for end hour
if t.After(rit.getRightMargin(t)) {
return false
}
return true
}
示例4: FmtDateFull
// FmtDateFull returns the full date representation of 't' for 'ti_ER'
func (ti *ti_ER) FmtDateFull(t time.Time) string {
b := make([]byte, 0, 32)
b = append(b, ti.daysWide[t.Weekday()]...)
b = append(b, []byte{0xe1, 0x8d, 0xa1, 0x20}...)
if t.Day() < 10 {
b = append(b, '0')
}
b = strconv.AppendInt(b, int64(t.Day()), 10)
b = append(b, []byte{0x20}...)
b = append(b, ti.monthsWide[t.Month()]...)
b = append(b, []byte{0x20, 0xe1, 0x88, 0x98, 0xe1, 0x8b, 0x93, 0xe1, 0x88, 0x8d, 0xe1, 0x89, 0xb2, 0x20}...)
b = strconv.AppendInt(b, int64(t.Year()), 10)
b = append(b, []byte{0x20}...)
if t.Year() < 0 {
b = append(b, ti.erasWide[0]...)
} else {
b = append(b, ti.erasWide[1]...)
}
return string(b)
}
示例5: isStartOfMonth
func isStartOfMonth(t time.Time) bool {
y := t.Year()
m := t.Month()
utcLoc, _ := time.LoadLocation("UTC")
startOfMonth := time.Date(y, m, 1, 0, 0, 0, 0, utcLoc)
return t.Equal(startOfMonth)
}
示例6: DateFilepath
func (f FileSystem) DateFilepath(date time.Time) string {
filename := fmt.Sprintf("%s_%s_%d_%d.md", date.Weekday(), date.Month().String(), date.Day(), date.Year())
path := path.Join(f.MonthDirectory(date), strings.ToLower(filename))
f.bootstrap(path)
return path
}
示例7: Crawl
// Crawl 获取公司每天的报价
func (yahoo YahooFinance) Crawl(_market market.Market, company market.Company, date time.Time) (*market.CompanyDailyQuote, error) {
// 起止时间
start := time.Date(date.Year(), date.Month(), date.Day(), 0, 0, 0, 0, date.Location())
end := start.AddDate(0, 0, 1)
pattern := "https://finance-yql.media.yahoo.com/v7/finance/chart/%s?period2=%d&period1=%d&interval=1m&indicators=quote&includeTimestamps=true&includePrePost=true&events=div%%7Csplit%%7Cearn&corsDomain=finance.yahoo.com"
url := fmt.Sprintf(pattern, _market.YahooQueryCode(company), end.Unix(), start.Unix())
// 查询Yahoo财经接口,返回股票分时数据
str, err := net.DownloadStringRetry(url, yahoo.RetryCount(), yahoo.RetryInterval())
if err != nil {
return nil, err
}
// 解析Json
quote := &YahooQuote{}
err = json.Unmarshal([]byte(str), "e)
if err != nil {
return nil, err
}
// 校验
err = yahoo.valid(quote)
if err != nil {
return nil, err
}
// 解析
return yahoo.parse(_market, company, date, quote)
}
示例8: NextAfter
func (self Day) NextAfter(t time.Time) (time.Time, error) {
desiredDay := int(self)
if desiredDay == Last {
if isLastDayInMonth(t) {
return t.AddDate(0, 0, 1).AddDate(0, 1, -1), nil
}
return firstDayOfMonth(t).AddDate(0, 2, -1), nil
}
if t.Day() > desiredDay {
if isLastDayInMonth(t) && desiredDay == First {
return t.AddDate(0, 0, 1), nil
}
return self.NextAfter(t.AddDate(0, 0, 1))
}
if t.Day() < desiredDay {
totalDays := lastDayOfMonth(t).Day()
if totalDays < desiredDay {
return self.NextAfter(t.AddDate(0, 1, 0))
}
return time.Date(t.Year(), t.Month(), desiredDay, 0, 0, 0, 0, t.Location()), nil
}
totalDaysNextMonth := lastDayOfMonth(lastDayOfMonth(t).AddDate(0, 0, 1)).Day()
if totalDaysNextMonth < desiredDay {
return self.NextAfter(t.AddDate(0, 2, -1))
}
return t.AddDate(0, 1, 0), nil
}
示例9: yqlHist
func yqlHist(symbols []string, start *time.Time, end *time.Time) (map[string]fquery.Hist, error) {
if start == nil {
t := time.Date(2000, time.January, 1, 0, 0, 0, 0, time.UTC)
start = &t
}
startq := fmt.Sprintf(` AND startDate = "%v-%v-%v"`,
start.Year(), int(start.Month()), start.Day())
if end == nil {
t := time.Now()
end = &t
}
endq := fmt.Sprintf(` AND endDate = "%v-%v-%v"`,
end.Year(), int(end.Month()), end.Day())
queryGen := func(symbol string) string {
return fmt.Sprintf(
`SELECT * FROM yahoo.finance.historicaldata WHERE symbol="%s"`,
symbol) + startq + endq
}
makeMarshal := func() interface{} {
var resp YqlJsonHistResponse
return &resp
}
res := make(map[string]fquery.Hist)
parallelFetch(queryGen, makeMarshal, addHistToMap(res), symbols)
return res, nil
}
示例10: FmtDateShort
// FmtDateShort returns the short date representation of 't' for 'bg_BG'
func (bg *bg_BG) FmtDateShort(t time.Time) string {
b := make([]byte, 0, 32)
b = strconv.AppendInt(b, int64(t.Day()), 10)
b = append(b, []byte{0x2e}...)
if t.Month() < 10 {
b = append(b, '0')
}
b = strconv.AppendInt(b, int64(t.Month()), 10)
b = append(b, []byte{0x2e}...)
if t.Year() > 9 {
b = append(b, strconv.Itoa(t.Year())[2:]...)
} else {
b = append(b, strconv.Itoa(t.Year())[1:]...)
}
b = append(b, []byte{0x20, 0xd0, 0xb3}...)
b = append(b, []byte{0x2e}...)
return string(b)
}
示例11: nextMonth
func (expr *Expression) nextMonth(t time.Time) time.Time {
// Find index at which item in list is greater or equal to
// candidate month
i := sort.SearchInts(expr.monthList, int(t.Month())+1)
if i == len(expr.monthList) {
return expr.nextYear(t)
}
// Month changed, need to recalculate actual days of month
expr.actualDaysOfMonthList = expr.calculateActualDaysOfMonth(t.Year(), expr.monthList[i])
if len(expr.actualDaysOfMonthList) == 0 {
return expr.nextMonth(time.Date(
t.Year(),
time.Month(expr.monthList[i]),
1,
expr.hourList[0],
expr.minuteList[0],
expr.secondList[0],
0,
t.Location()))
}
return time.Date(
t.Year(),
time.Month(expr.monthList[i]),
expr.actualDaysOfMonthList[0],
expr.hourList[0],
expr.minuteList[0],
expr.secondList[0],
0,
t.Location())
}
示例12: Strftime
func Strftime(format string, t time.Time) (timestamp string, err error) {
c_format := C.CString(format)
defer func() { C.free(unsafe.Pointer(c_format)) }()
tz, offset := t.Zone()
c_tz := C.CString(tz)
defer func() { C.free(unsafe.Pointer(c_tz)) }()
c_time := C.struct_tm{
tm_year: C.int(t.Year() - 1900),
tm_mon: C.int(t.Month() - 1),
tm_mday: C.int(t.Day()),
tm_hour: C.int(t.Hour()),
tm_min: C.int(t.Minute()),
tm_sec: C.int(t.Second()),
tm_gmtoff: C.long(offset),
tm_zone: c_tz,
}
c_timestamp, trr := C.ftime(c_format, &c_time)
defer func() { C.free(unsafe.Pointer(c_timestamp)) }()
timestamp = C.GoString(c_timestamp)
if trr == nil {
timestamp = C.GoString(c_timestamp)
} else {
err = fmt.Errorf("%s - %s", trr, t)
}
return
}
示例13: ParseTime
func ParseTime(str string) (time.Time, error) {
now := time.Now()
t := time.Time{}
var err error
isShortTime := false
for _, tfmt := range inputTimeFormats {
t, err = time.ParseInLocation(tfmt, str, time.Local)
if err == nil {
if tfmt == "03:04 pm" || tfmt == "3:04 pm" || tfmt == "15:04" {
isShortTime = true
}
break
}
// fmt.Printf("%s \n", tfmt)
}
// if no year or month or day was given fill those in with todays date
if isShortTime {
t = time.Date(now.Year(), now.Month(), now.Day(), t.Hour(), t.Minute(), t.Second(), 0, time.Local)
} else if t.Year() == 0 { // no year was specified
t = time.Date(now.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second(), 0, time.Local)
}
return t, err
}
示例14: createDate
func createDate(str string, now time.Time) time.Time {
arr := strings.Split(str, "-")
year, _ := strconv.Atoi(arr[0])
month, _ := strconv.Atoi(arr[1])
day, _ := strconv.Atoi(arr[2])
return now.AddDate(year-now.Year(), month-int(now.Month()), day-now.Day())
}
示例15: WorkdayN
// WorkdayN reports the day of the month that corresponds to the nth workday
// for the given year and month.
//
// The value of n affects the direction of counting:
// n > 0: counting begins at the first day of the month.
// n == 0: the result is always 0.
// n < 0: counting begins at the end of the month.
func (c *Calendar) WorkdayN(year int, month time.Month, n int) int {
var date time.Time
var add int
if n == 0 {
return 0
}
if n > 0 {
date = time.Date(year, month, 1, 12, 0, 0, 0, time.UTC)
add = 1
} else {
date = time.Date(year, month+1, 1, 12, 0, 0, 0, time.UTC).AddDate(0, 0, -1)
add = -1
n = -n
}
ndays := 0
for ; month == date.Month(); date = date.AddDate(0, 0, add) {
if c.IsWorkday(date) {
ndays++
if ndays == n {
return date.Day()
}
}
}
return 0
}