Home > API Reference
Complete documentation for all GoTime functions and their usage patterns.
- Parsing & Formatting - Parse, Format, FormatTimestamp, FormatUnix functions
- Date Conversion - Convert function and format transformation patterns
- Relative Time Functions - TimeAgo, Days, Weeks, Months, Years functions
- Time Calculations - Latest, Earliest, Diff, WorkDay, business day functions
- Date Range Operations - IsBetween, range validation, overlap detection
- Utility Functions - TruncateTime, DateValue, timezone helpers, time boundaries
- Calendar Math - DayOfYear, WeekOfMonth, month boundary checks
Parse date/time strings in various formats:
Parse(dateString, format)- Parse with NITES formatParseInLocation(dateString, format, location)- Parse in specific timezone
Format time.Time values to strings:
Format(time, format)- Format with NITES formatFormatTimestamp(timestamp, format)- Format Unix timestampFormatUnix(timestamp, format)- Format Unix timestamp (alias)
Transform between different formats:
Convert(dateString, fromFormat, toFormat)- Convert format while preserving value
Human-readable time differences:
TimeAgo(time)- "2 hours ago", "3 days ago", etc.Days(n, from)- Add/subtract daysWeeks(n, from)- Add/subtract weeksMonths(n, from)- Add/subtract monthsYears(n, from)- Add/subtract years
Precise time-level arithmetic operations:
Hours(n, from)- Add/subtract hoursMinutes(n, from)- Add/subtract minutesSeconds(n, from)- Add/subtract seconds
Advanced time calculations:
Latest(times...)- Find latest timeEarliest(times...)- Find earliest timeDiff(time1, time2, unit)- Calculate differenceWorkDay(n, from)- Add/subtract work daysPrevWorkDay(time)- Find previous work dayNetWorkDays(start, end)- Count business days
Age and time difference calculations:
Age(birthDate)- Calculate current ageYearsBetween(start, end)- Years between datesMonthsBetween(start, end)- Months between datesDaysBetween(start, end)- Days between datesWeeksBetween(start, end)- Weeks between datesDurationInWords(start, end)- Human-readable durationIsValidAge(age)- Validate age reasonableness
Quarterly time operations for business applications:
QuarterStart(time)- Start of quarterQuarterEnd(time)- End of quarterLastQuarter(time)- Previous quarter startNextQuarter(time)- Next quarter startQuarters(start, end)- List quarters in rangeQuarterOfYear(time)- Get quarter number (1-4)
Date range operations:
IsBetween(time, start, end)- Check if time is in rangeIsBetweenDates(time, start, end)- Check if date is in range (ignoring time)
Helper functions for common tasks:
TruncateTime(time)- Remove time componentDateValue(input)- Convert various types to time.TimeSoD(time)/EoD(time)- Start/end of dayWeekStart(time)/WeekEnd(time)- Week boundariesMonthStart(time)/MonthEnd(time)- Month boundariesIsLeapYear(year)- Check leap yearDaysInMonth(year, month)- Days in monthIsWeekend(time)/IsWeekday(time)- Day type checking
Calendar calculation utilities:
DayOfYear(time)- Day number within year (1-366)WeekOfMonth(time)- Week number within month (1-5)IsFirstDayOfMonth(time)- Check if first day of monthIsLastDayOfMonth(time)- Check if last day of month
// Parse and format
date, _ := gotime.Parse("2025-07-07", "yyyy-mm-dd")
formatted := gotime.Format(date, "wwww, mmmm dd, yyyy")
// Convert formats
converted, _ := gotime.Convert("07/07/2025", "mm/dd/yyyy", "yyyy-mm-dd")
// Relative time
relative := gotime.TimeAgo(date)
// Time arithmetic
futureTime := gotime.Hours(3, time.Now()) // 3 hours from now
pastTime := gotime.Minutes(-30, time.Now()) // 30 minutes ago// Business day calculations
workDay := gotime.WorkDay(5, time.Now()) // 5 business days from now
businessDays := gotime.NetWorkDays(start, end) // Count business days
// Age calculations
age := gotime.Age(birthDate) // Current age
years := gotime.YearsBetween(start, end) // Years between dates
duration := gotime.DurationInWords(start, end) // "2 years, 3 months"
// Quarter operations
quarterStart := gotime.QuarterStart(time.Now()) // Start of current quarter
quarters := gotime.Quarters(start, end) // All quarters in range
// Range operations
inRange := gotime.IsBetween(check, start, end) // Check if in range
latest := gotime.Latest(time1, time2, time3) // Find latest time
// Date boundaries
dayStart := gotime.SoD(date) // Start of day
monthEnd := gotime.MonthEnd(date) // End of monthdate, err := gotime.Parse("invalid", "yyyy-mm-dd")
if err != nil {
// Handle parsing error
fmt.Printf("Parse error: %v\n", err)
}
converted, err := gotime.Convert("2025-13-01", "yyyy-mm-dd", "mm/dd/yyyy")
if err != nil {
// Handle invalid date
fmt.Printf("Invalid date: %v\n", err)
}GoTime uses human-readable format specifiers instead of Go's reference time approach:
| NITES | Description | Example |
|---|---|---|
yyyy |
4-digit year | 2025 |
yy |
2-digit year | 25 |
mm |
Month (zero-padded) | 07 |
mmm |
Month abbreviation | Jul |
mmmm |
Full month name | July |
dd |
Day (zero-padded) | 07 |
d |
Day (no padding) | 7 |
hh |
Hour (24-hour, zero-padded) | 14 |
h |
Hour (24-hour, no padding) | 14 |
ii |
Minutes (zero-padded) | 30 |
i |
Minutes (no padding) | 30 |
ss |
Seconds (zero-padded) | 45 |
s |
Seconds (no padding) | 45 |
www |
Weekday abbreviation | Mon |
wwww |
Full weekday name | Monday |
See Core Concepts - NITES for complete reference.
- Cache parsed formats for repeated operations
- Use TruncateTime() for date-only comparisons
- Batch timezone conversions when possible
- Pre-validate input formats in data processing pipelines
- Use IsBetweenDates() for date ranges ignoring time
- Always check errors from Parse and Convert functions
- Validate date ranges before processing
- Use default values for optional parameters
- Log parsing errors with context for debugging
- Implement fallback formats for flexible parsing
- Getting Started Guide - Quick introduction
- Core Concepts - Understanding GoTime principles
- Examples & Use Cases - Real-world implementations
- GitHub Issues - Bug reports and feature requests
Navigate to specific function documentation using the links above, or browse the complete API reference for detailed examples and use cases.