1234567891011121314151617181920212223242526272829303132 |
- package datetime
- import (
- "fmt"
- "time"
- "git.dmitriygnatenko.ru/dima/dmitriygnatenko-v2/internal/services/i18n"
- )
- const (
- dateTimeFormat = "2006-01-02"
- yearFormat = "2006"
- monthFormat = "01"
- dateFormat = "02"
- dayFormat = "2"
- )
- func ParseDateTime(dateTime string) (time.Time, error) {
- return time.Parse(dateTimeFormat, dateTime)
- }
- func FormatDateStr(lang i18n.Lang, date time.Time) string {
- return date.Format(dayFormat) + " " + getMonthStr(lang, date.Format(monthFormat)) + " " + date.Format(yearFormat)
- }
- func FormatDateForm(date time.Time) string {
- return date.Format(yearFormat) + "-" + date.Format(monthFormat) + "-" + date.Format(dateFormat)
- }
- func getMonthStr(lang i18n.Lang, month string) string {
- return i18n.T(lang, fmt.Sprintf("m%s", month))
- }
|