123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- package timefmt
- import (
- "strings"
- "time"
- )
- type TimeFormatter struct {
- printer *TimePrinter
- multiline bool
- }
- func (this *TimeFormatter) Format(t time.Time) string {
- fs := this.printer.PrintTime(t)
- if this.multiline {
- return fs
- } else {
- fs = strings.Replace(fs, "\r", "", -1)
- fs = strings.Replace(fs, "\n", "", -1)
- return fs
- }
- return this.printer.PrintTime(t)
- }
- func (this *TimeFormatter) ForceTimezone(tz *time.Location) {
- this.printer.UseTimezone(tz)
- }
- func (this *TimeFormatter) ForceLocalTimezone() {
- this.printer.UseLocalTimezone()
- }
- func (this *TimeFormatter) ForceUTC() {
- this.printer.UseUTC()
- }
- func NewTimeFormatter(fmtstr string, multiline bool) *TimeFormatter {
- tf := &TimeFormatter{
- printer: NewTimePrinter(),
- multiline: multiline,
- }
- parser := NewFormatParser()
- parser.ParseFormatString(tf.printer, fmtstr)
- return tf
- }
|