本文整理汇总了Golang中Time.Time.Day方法的典型用法代码示例。如果您正苦于以下问题:Golang Time.Day方法的具体用法?Golang Time.Day怎么用?Golang Time.Day使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Time.Time
的用法示例。
在下文中一共展示了Time.Day方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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())
}
示例2: SetRange
func (de *DateEdit) SetRange(min, max time.Time) error {
if !min.IsZero() && !max.IsZero() {
if min.Year() > max.Year() ||
min.Year() == max.Year() && min.Month() > max.Month() ||
min.Year() == max.Year() && min.Month() == max.Month() && min.Day() > max.Day() {
return newError("invalid range")
}
}
var st [2]win.SYSTEMTIME
var wParam uintptr
if !min.IsZero() {
wParam |= win.GDTR_MIN
st[0] = *de.timeToSystemTime(min)
}
if !max.IsZero() {
wParam |= win.GDTR_MAX
st[1] = *de.timeToSystemTime(max)
}
if 0 == de.SendMessage(win.DTM_SETRANGE, wParam, uintptr(unsafe.Pointer(&st[0]))) {
return newError("SendMessage(DTM_SETRANGE)")
}
return nil
}
示例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: TimeToAnneesMoisJour
// Crée un nouvel objet de type AnneesMoisJours pour la date spécifiée
func TimeToAnneesMoisJour(t time.Time) (AnneesMoisJours, error) {
if t.IsZero() {
return AnneesMoisJours{}, ErrDateFormatInvalide
}
return AnneesMoisJours{t.Year(), int(t.Month()), t.Day()}, nil
}
示例6: substractMonth
func substractMonth(now time.Time) time.Time {
var previousMonth time.Month
year := now.Year()
switch now.Month() {
case time.January:
previousMonth = time.December
year = year - 1
case time.February:
previousMonth = time.January
case time.March:
previousMonth = time.February
case time.April:
previousMonth = time.March
case time.May:
previousMonth = time.April
case time.June:
previousMonth = time.May
case time.July:
previousMonth = time.June
case time.August:
previousMonth = time.July
case time.September:
previousMonth = time.August
case time.October:
previousMonth = time.September
case time.November:
previousMonth = time.October
case time.December:
previousMonth = time.November
}
return time.Date(year, previousMonth, now.Day(), 12, 0, 0, 0, time.UTC)
}
示例7: getFetchLink
func getFetchLink(symbol string, currentDate time.Time) string {
// var currentDate time.Time = time.Now()
var result string = fmt.Sprintf(
"http://real-chart.finance.yahoo.com/table.csv?s=%s&a=00&b=1&c=1900&d=%02d&e=%02d&f=%d&g=d&ignore=.csv",
symbol, (currentDate.Month() - 1), currentDate.Day(), currentDate.Year())
return result
}
示例8: 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
}
示例9: TimeToString
func TimeToString(t time.Time) string {
year := t.Year()
month := int(t.Month())
day := t.Day()
result := strconv.Itoa(year) + "-" + strconv.Itoa(month) + "-" + strconv.Itoa(day)
return result
}
示例10: IsOccurring
// Implement Schedule interface.
func (self Day) IsOccurring(t time.Time) bool {
if self := int(self); self == Last {
return isLastDayInMonth(t)
} else {
return self == t.Day()
}
}
示例11: 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
}
示例12: 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)
}
示例13: 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
}
示例14: 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
}
示例15: buildTimeElement
func buildTimeElement(t time.Time) string {
return fmt.Sprintf(
"<dateTime.iso8601>%d%d%dT%d:%d:%d</dateTime.iso8601>",
t.Year(), t.Month(), t.Day(),
t.Hour(), t.Minute(), t.Second(),
)
}