當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Time.MarshalText方法代碼示例

本文整理匯總了Golang中Time.Time.MarshalText方法的典型用法代碼示例。如果您正苦於以下問題:Golang Time.MarshalText方法的具體用法?Golang Time.MarshalText怎麽用?Golang Time.MarshalText使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Time.Time的用法示例。


在下文中一共展示了Time.MarshalText方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: timev

func (e *encoder) timev(tag string, in time.Time) {
	s, err := in.MarshalText()
	if err != nil {
		failf("could not marshal text from input time %s: %s", in, err)
	}
	e.emitScalar(string(s), "", tag, yaml_PLAIN_SCALAR_STYLE)
}
開發者ID:mozilla-services,項目名稱:userplex,代碼行數:7,代碼來源:encode.go

示例2: marshalTime

func marshalTime(t time.Time) string {
	if t.IsZero() {
		return ""
	}
	b, _ := t.MarshalText()
	return string(b)
}
開發者ID:bridgewell,項目名稱:bosun,代碼行數:7,代碼來源:sched.go

示例3: markUpdated

func (m *baseModel) markUpdated(id string, t time.Time, conn redis.Conn) error {
	defer syncFS()

	ts, err := t.MarshalText()
	if err != nil {
		return err
	}
	_, err = conn.Do("HSET", m.idType+"s:updated", id, ts)
	return err
}
開發者ID:kpernyer,項目名稱:sphere-go-homecloud,代碼行數:10,代碼來源:baseModel.go

示例4: MarshalTime

// Converts Time t into a Unix timestamp with nanosecond precision
// in the format of: s.nnnnnnnnn
func MarshalTime(t time.Time) ([]byte, error) {

	if unixTime == true {
		sec := t.Unix()
		nsec := t.Nanosecond()

		return []byte(fmt.Sprintf("%d.%09d", sec, nsec)), nil
	} else {
		return t.MarshalText()
	}
}
開發者ID:cardi,項目名稱:timefind,代碼行數:13,代碼來源:time.go

示例5: RawNotificationsSince

func (c *Client) RawNotificationsSince(since time.Time) (*Notifications, error) {
	since = since.In(ZuluTime).Truncate(time.Second)

	rfcSince, err := since.MarshalText()
	if err != nil {
		return nil, err
	}

	url := "https://api.ft.com/content/notifications/?since=" + string(rfcSince)
	result := &Notifications{}
	raw, err := c.FromURL(url, result)
	result.RawJSON = raw
	return result, err
}
開發者ID:Financial-Times,項目名稱:go-ftapi,代碼行數:14,代碼來源:notifications.go

示例6: updateEventTimestamp

func (r *remote) updateEventTimestamp(t time.Time) {
	f, err := os.OpenFile(r.eventTsPath, syscall.O_CREAT|syscall.O_WRONLY|syscall.O_TRUNC, 0600)
	if err != nil {
		logrus.Warnf("libcontainerd: failed to open event timestamp file: %v", err)
		return
	}
	defer f.Close()

	b, err := t.MarshalText()
	if err != nil {
		logrus.Warnf("libcontainerd: failed to encode timestamp: %v", err)
		return
	}

	n, err := f.Write(b)
	if err != nil || n != len(b) {
		logrus.Warnf("libcontainerd: failed to update event timestamp file: %v", err)
		f.Truncate(0)
		return
	}
}
開發者ID:msabansal,項目名稱:docker,代碼行數:21,代碼來源:remote_unix.go

示例7: Fuzz

func Fuzz(data []byte) int {
	var t time.Time
	if err := t.UnmarshalText(data); err != nil {
		return 0
	}
	data1, err := t.MarshalText()
	if err != nil {
		panic(err)
	}
	var t1 time.Time
	if err := t1.UnmarshalText(data1); err != nil {
		panic(err)
	}
	if !fuzz.DeepEqual(t, t1) {
		fmt.Printf("t0: %#v\n", t)
		fmt.Printf("t1: %#v\n", t1)
		panic("bad MarshalText")
	}

	data2, err := t.GobEncode()
	if err != nil {
		panic(err)
	}
	var t2 time.Time
	if err := t2.GobDecode(data2); err != nil {
		panic(err)
	}
	if !fuzz.DeepEqual(t, t2) {
		fmt.Printf("t0: %#v\n", t)
		fmt.Printf("t2: %#v\n", t2)
		panic("bad GobEncode")
	}

	data3, err := t.MarshalBinary()
	if err != nil {
		panic(err)
	}
	var t3 time.Time
	if err := t3.UnmarshalBinary(data3); err != nil {
		panic(err)
	}
	if !fuzz.DeepEqual(t, t3) {
		fmt.Printf("t0: %#v\n", t)
		fmt.Printf("t3: %#v\n", t3)
		panic("bad MarshalBinary")
	}

	data4, err := t.MarshalJSON()
	if err != nil {
		panic(err)
	}
	var t4 time.Time
	if err := t4.UnmarshalJSON(data4); err != nil {
		panic(err)
	}
	if !fuzz.DeepEqual(t, t4) {
		fmt.Printf("t0: %#v\n", t)
		fmt.Printf("t4: %#v\n", t4)
		panic("bad MarshalJSON")
	}

	data5, err := t.MarshalText()
	if err != nil {
		panic(err)
	}
	var t5 time.Time
	if err := t5.UnmarshalText(data5); err != nil {
		panic(err)
	}
	if !fuzz.DeepEqual(t, t5) {
		fmt.Printf("t0: %#v\n", t)
		fmt.Printf("t5: %#v\n", t5)
		panic("bad MarshalText")
	}

	data6 := t.Format(time.RFC3339Nano)
	t6, err := time.Parse(time.RFC3339Nano, data6)
	if err != nil {
		panic(err)
	}
	if !fuzz.DeepEqual(t, t6) {
		fmt.Printf("t0: %#v\n", t)
		fmt.Printf("t6: %#v\n", t6)
		panic("bad Format")
	}
	return 1
}
開發者ID:sjn1978,項目名稱:go-fuzz,代碼行數:87,代碼來源:main.go


注:本文中的Time.Time.MarshalText方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。