当前位置: 首页>>代码示例>>Golang>>正文


Golang Time.Month函数代码示例

本文整理汇总了Golang中Time.Month函数的典型用法代码示例。如果您正苦于以下问题:Golang Month函数的具体用法?Golang Month怎么用?Golang Month使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Month函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: main

func main() {
	flag.Parse()

	var now = time.Now()
	if *month == -1 {
		*month = int(now.Month())
	}
	if *year == -1 {
		*year = now.Year()
	}

	r, err := leaveFile(*year)
	if err != nil {
		log.Fatal(err)
	}

	leave := &Leave{}
	json.NewDecoder(r).Decode(leave)

	startDate := time.Date(*year, time.Month(*month), 1, 0, 0, 0, 0, time.UTC)
	endDate := time.Date(*year, time.Month(*month+1), -1, 0, 0, 0, 0, time.UTC)

	expectedWorkTime := leave.expectedWorkTime(startDate, endDate)
	totalled := summarize(traq.TotalDate(*project, traq.ContentLoader, traq.DatesInMonth(*year, *month)...))

	fmt.Printf("work time for %4d-%02d: %2.2f vs %2.2f\n", *year, *month, float64(expectedWorkTime)/60.0/60.0, float64(totalled)/60.0/60.0)
}
开发者ID:nicolai86,项目名称:traq,代码行数:27,代码来源:main.go

示例2: 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())
}
开发者ID:ZhuHangpeng,项目名称:mig,代码行数:31,代码来源:cronexpr_next.go

示例3: ExampleTime

func ExampleTime() {
	// Example 19.a, p. 121.
	r1 := unit.AngleFromDeg(113.56833)
	d1 := unit.AngleFromDeg(31.89756)
	r2 := unit.AngleFromDeg(116.25042)
	d2 := unit.AngleFromDeg(28.03681)
	r3 := make([]unit.Angle, 5)
	for i, ri := range []float64{
		118.98067, 119.59396, 120.20413, 120.81108, 121.41475} {
		r3[i] = unit.AngleFromDeg(ri)
	}
	d3 := make([]unit.Angle, 5)
	for i, di := range []float64{
		21.68417, 21.58983, 21.49394, 21.39653, 21.29761} {
		d3[i] = unit.AngleFromDeg(di)
	}
	// use JD as time to handle month boundary
	jd, err := line.Time(r1, d1, r2, d2, r3, d3,
		julian.CalendarGregorianToJD(1994, 9, 29),
		julian.CalendarGregorianToJD(1994, 10, 3))
	if err != nil {
		fmt.Println(err)
		return
	}
	y, m, d := julian.JDToCalendar(jd)
	dInt, dFrac := math.Modf(d)
	fmt.Printf("%d %s %.4f\n", y, time.Month(m), d)
	fmt.Printf("%d %s %d, at %h TD(UT)\n", y, time.Month(m), int(dInt),
		sexa.FmtTime(unit.TimeFromDay(dFrac)))
	// Output:
	// 1994 October 1.2233
	// 1994 October 1, at 5ʰ TD(UT)
}
开发者ID:soniakeys,项目名称:meeus,代码行数:33,代码来源:line_test.go

示例4: ExampleTime

func ExampleTime() {
	// Example 19.a, p. 121.

	// convert degree data to radians
	r1 := 113.56833 * math.Pi / 180
	d1 := 31.89756 * math.Pi / 180
	r2 := 116.25042 * math.Pi / 180
	d2 := 28.03681 * math.Pi / 180
	r3 := make([]float64, 5)
	for i, ri := range []float64{
		118.98067, 119.59396, 120.20413, 120.81108, 121.41475} {
		r3[i] = ri * math.Pi / 180
	}
	d3 := make([]float64, 5)
	for i, di := range []float64{
		21.68417, 21.58983, 21.49394, 21.39653, 21.29761} {
		d3[i] = di * math.Pi / 180
	}
	// use JD as time to handle month boundary
	jd, err := line.Time(r1, d1, r2, d2, r3, d3,
		julian.CalendarGregorianToJD(1994, 9, 29),
		julian.CalendarGregorianToJD(1994, 10, 3))
	if err != nil {
		fmt.Println(err)
		return
	}
	y, m, d := julian.JDToCalendar(jd)
	dInt, dFrac := math.Modf(d)
	fmt.Printf("%d %s %.4f\n", y, time.Month(m), d)
	fmt.Printf("%d %s %d, at %h TD(UT)\n", y, time.Month(m), int(dInt),
		sexa.NewFmtTime(dFrac*24*3600))
	// Output:
	// 1994 October 1.2233
	// 1994 October 1, at 5ʰ TD(UT)
}
开发者ID:thecc4re,项目名称:meeus,代码行数:35,代码来源:line_test.go

示例5: TestTimezone

func TestTimezone(t *testing.T) {
	location, _ := time.LoadLocation("America/New_York")
	println(location.String())
	year := 2015
	month := 1
	day := 11
	hour := 13
	minute := 57

	localTime := time.Date(year, time.Month(month), day, hour, minute, 0, 0, location)
	//	utcTime := localTime.UTC()

	fmt.Println("localtime:", localTime)

	//	var t0=time.Now()
	//offset = 秒
	zoneName, offset := localTime.Local().Zone()
	println("zone name is:%s,offset is:%d", zoneName, offset)
	newtime := localTime.Add(time.Duration(offset * 1000000000))
	fmt.Println("newtime:", newtime)

	startDay, _ := time.Parse("2006-01-02", "2015-02-12")
	localTime = time.Date(2015, time.Month(2), 12, 0, 0, 0, 0, time.Local)

	fmt.Println("xht:", startDay.Local())
	fmt.Println("xht1:", localTime)

	t1 := time.Now()
	fmt.Println("diff is:", t1)
	year, month, day = convert2ymd("2015-09-28")
	println("xht2:", year, month, day)
}
开发者ID:xiongtoto0526,项目名称:Scirpt,代码行数:32,代码来源:dao_test.go

示例6: TestTime2

func TestTime2(t *testing.T) {
	fmt.Println("test time 2:")

	const f = "2006-01-02 15:04:05.999999999 -07:00"
	in := []time.Time{}

	tm, err := time.Parse(f, "2015-01-23 12:34:56.123456789 +09:05")
	if err != nil {
		t.Fatal(err)
	}
	in = append(in, tm)

	tm, err = time.Parse(f, "1014-10-14 21:43:50.987654321 -08:50")
	if err != nil {
		t.Fatal(err)
	}
	in = append(in, tm)

	tm = time.Date(-4123, time.Month(12), 1, 2, 3, 4, 0, time.UTC)
	in = append(in, tm)

	tm = time.Date(9321, time.Month(11), 2, 3, 4, 5, 0, time.UTC)
	in = append(in, tm)

	r := sqlstestv(DB(), t, "select :0, :1, :2, :3  from dual", in[0], in[1], in[2], in[3])
	for i, v := range r {
		vt := v.(time.Time)
		if !vt.Equal(in[i]) {
			t.Fatal(vt, "!=", in[i])
		}
	}
}
开发者ID:tianlin,项目名称:go-oci8,代码行数:32,代码来源:more_test.go

示例7: main

func main() {
	cal, err := calendar.NewCalendar("en_US", true)
	if err != nil {
		panic("Could not create a US calendar!")
	}

	//year := time.Now().Year()
	year := 2016

	// When is easter this year?
	easter := calendar.EasterDay(year)
	fmt.Printf("Easter %d is at %s\n", year, easter.String()[:10])

	// Show some info for March this year
	//datebonanza(year, time.Month(3))

	// Show some info for March 2000
	//datebonanza(2000, time.Month(3))

	// Show some info for the current month
	datebonanza(cal, year, time.Month(time.Now().Month()))

	notable(cal, year)
	notable(cal, year+1)

	flag(cal, year)

	fmt.Println(cal.DayName(1))
	fmt.Println(cal.MonthName(time.Month(12)))
}
开发者ID:xyproto,项目名称:moskus,代码行数:30,代码来源:main.go

示例8: DaysInMonth

// DaysInMonth returns an array of all the days in the given month in the given
// year. Designed for use with html/template's `range` utility.
func DaysInMonth(y int, m Month) []time.Time {
	r := []time.Time{time.Date(y, time.Month(m), 1, 0, 0, 0, 0, time.UTC)}
	for i := 2; i <= m.lastDay(uint16(y)); i++ {
		r = append(r, time.Date(y, time.Month(m), i, 0, 0, 0, 0, time.UTC))
	}

	return r
}
开发者ID:bentranter,项目名称:startupweekend2016,代码行数:10,代码来源:month.go

示例9: getDaysBetweenSolar

/**
 * 计算两个公历日期之间的天数
 */
func getDaysBetweenSolar(year, month, day, year1, month1, day1 int32) (int64, bool) {
	date := time.Date(int(year), time.Month(month), int(day),
		0, 0, 0, 0, time.UTC).Unix()
	date1 := time.Date(int(year1), time.Month(month1), int(day1),
		0, 0, 0, 0, time.UTC).Unix()

	return (date1 - date) / 86400, true
}
开发者ID:jouyouyun,项目名称:lunarcalendar,代码行数:11,代码来源:calendar.go

示例10: TestBindDefine_OraIntervalDS_ShiftTime_session

func TestBindDefine_OraIntervalDS_ShiftTime_session(t *testing.T) {
	interval := ora.IntervalDS{Day: 1, Hour: 1, Minute: 1, Second: 1, Nanosecond: 123456789}
	actual := interval.ShiftTime(time.Date(2000, time.Month(1), 1, 0, 0, 0, 0, time.Local))
	expected := time.Date(2000, time.Month(1), 2, 1, 1, 1, 123456789, time.Local)
	if !expected.Equal(actual) {
		t.Fatalf("expected(%v), actual(%v)", expected, actual)
	}
}
开发者ID:optimuse,项目名称:ora,代码行数:8,代码来源:z_interval_session_test.go

示例11: TestDateRange

func TestDateRange(t *testing.T) {
	d := NewDateRange(
		time.Date(1980, time.Month(1), 1, 0, 0, 0, 0, time.UTC),
		time.Date(1980, time.Month(12), 31, 0, 0, 0, 0, time.UTC),
		time.Duration(time.Hour*24*30))

	for i := d.Begin(); !i.Done(); i.Next() {
		log.Print("ITER: ", i.Time())
	}
}
开发者ID:yasushi-saito,项目名称:portopt,代码行数:10,代码来源:portopt_test.go

示例12: getMonth

func getMonth(buf string) (m time.Month) {
	if len(buf) == 3 {
		for i := 0; i < 12; i++ {
			if strings.ToLower(buf) == MONTHS[i] {
				return time.Month(i + 1)
			}
		}
	}
	return time.Month(-1)
}
开发者ID:shenwei356,项目名称:goftp,代码行数:10,代码来源:parse.go

示例13: Parse

// Parse extracts time from string-based info, with some constraints.
//
// The described time cannot be in the future, or more than 1000 years in the past.
//
// Note that month is 0-indexed, unlike time.Month.
func Parse(year, month, day, hourMinute string, loc *time.Location) (time.Time, error) {
	now := time.Now().In(loc)

	y64, err := strconv.ParseInt(year, 10, 0)
	y := int(y64)
	if err != nil {
		return time.Time{}, err
	}
	if y < now.Year()-1000 {
		return time.Time{}, fmt.Errorf("bad year; %d is too far in the past", y)
	}
	m, err := strconv.ParseInt(month, 10, 0)
	if err != nil {
		return time.Time{}, err
	}
	if m < 0 || m > 11 {
		return time.Time{}, fmt.Errorf("bad month: %d is not within [0, 11]", m)
	}
	// Month +1 since time.Month is [1, 12].
	m = m + 1
	d64, err := strconv.ParseInt(day, 10, 0)
	d := int(d64)
	if err != nil {
		return time.Time{}, err
	}
	if d < 1 {
		return time.Time{}, fmt.Errorf("bad day: %d; can't be negative", d)
	} else if d > daysIn(time.Month(m), y) {
		return time.Time{}, fmt.Errorf("bad day: %d; only %d days in %v, %d", d, daysIn(time.Month(m), y), time.Month(m), y)
	}
	parts := strings.Split(hourMinute, ":")
	if len(parts) != 2 {
		return time.Time{}, fmt.Errorf("bad hour/minute: %s", hourMinute)
	}
	h, err := strconv.ParseInt(parts[0], 10, 0)
	if err != nil {
		return time.Time{}, err
	}
	if h < 0 || h > 60 {
		return time.Time{}, fmt.Errorf("bad hour: %d", h)
	}
	min, err := strconv.ParseInt(parts[1], 10, 0)
	if err != nil {
		return time.Time{}, err
	}
	if min < 0 || min > 60 {
		return time.Time{}, fmt.Errorf("bad minute: %d", min)
	}

	t := time.Time(time.Date(int(y), time.Month(m), int(d), int(h), int(min), 0, 0, loc))
	if t.After(now) {
		return time.Time{}, fmt.Errorf("bad time; %v is in the future", time.Time(t))
	}
	return t, nil
}
开发者ID:hkjn,项目名称:timeutils,代码行数:60,代码来源:time.go

示例14: TestTimeSeriesExtend

func TestTimeSeriesExtend(t *testing.T) {
	start := time.Date(2016, time.Month(1), 25, 10, 0, 0, 0, time.UTC)
	step := time.Minute

	ts0, err := NewTimeSeriesOfData("test0", start, step, []float64{1, 2, 3})
	checkErr(t, err)
	ts1 := ts0.Copy()
	ts1.ExtendBy(3 * time.Minute)

	ts2 := ts0.Copy()
	ts2.ExtendTo(time.Date(2016, time.Month(1), 25, 10, 5, 0, 0, time.UTC))

	ts3 := ts0.Copy()
	ts3.ExtendWith([]float64{4, 5, 6})

	tss := []struct {
		Got *TimeSeries
		Exp *TimeSeries
	}{
		{
			Got: ts1,
			Exp: &TimeSeries{
				key:   "test0",
				start: start,
				step:  step,
				data:  []float64{1, 2, 3, NaN, NaN, NaN},
			},
		},
		{
			Got: ts2,
			Exp: &TimeSeries{
				key:   "test0",
				start: start,
				step:  step,
				data:  []float64{1, 2, 3, NaN, NaN, NaN},
			},
		},
		{
			Got: ts3,
			Exp: &TimeSeries{
				key:   "test0",
				start: start,
				step:  step,
				data:  []float64{1, 2, 3, 4, 5, 6},
			},
		},
	}

	for _, pair := range tss {
		fmt.Printf("%s\n%s\n\n", pair.Got, pair.Exp)
		checkTimeSeries(t, pair.Got, pair.Exp)
	}
}
开发者ID:datacratic,项目名称:gotsvis,代码行数:53,代码来源:time_series_test.go

示例15: Test_calculateEventD

func Test_calculateEventD(t *testing.T) {
	ipstr := [6]string{"*", "*", "03", "*", "*", "*"}
	baseTime := time.Date(2014, time.Month(1), 1, 4, 0, 0, 0, time.Local)
	expectedTime := time.Date(2014, time.Month(1), 2, 3, 0, 0, 10000, time.Local)
	cr := ParseInput(ipstr)
	if cr.calculateEvent(baseTime) != expectedTime {
		fmt.Println(cr.calculatedTime, expectedTime)
		t.Error("crontime: calculateEvent failed, 4")
	} else {
		t.Log("crontime: calculateEvent passed")
	}
}
开发者ID:Horrendus,项目名称:beehive,代码行数:12,代码来源:crontime_test.go


注:本文中的Time.Month函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。