duidui_fiber/pkg/utils/timeutil.go
2026-03-27 10:34:03 +08:00

24 lines
517 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package utils
import (
"database/sql"
"time"
)
// FormatNullTimeToStd 将 sql.NullTime 转换为标准时间字符串RFC3339格式
func FormatNullTimeToStd(nullTime sql.NullTime) string {
if !nullTime.Valid {
return ""
}
return nullTime.Time.Format(time.RFC3339)
}
// ParseTimeFromStd 将标准时间字符串RFC3339格式转换为 time.Time
func ParseTimeFromStd(timeStr string) (time.Time, error) {
if timeStr == "" {
return time.Time{}, nil
}
return time.Parse(time.RFC3339, timeStr)
}