Strings and Time in Go

Strings and Time is where your programs learn to work with text and dates.

In this chapter, you will:

  • create, join, compare, search, split and change text
  • understand runes, Unicode and UTF-8
  • build long text quickly with strings.Builder
  • make, change, compare and format dates, times and durations

What each lesson covers:

  • Strings: Create interpreted and raw strings, find the length, join, slice and compare text, use the strings package, understand runes, Unicode and UTF-8, and build text with strings.Builder.
  • Time and Date: Work with time.Time and time.Duration: get the current time, build and parse dates, read their parts, add, subtract and compare times, and format them with Go's reference layout.

This chapter has 2 lessons. Plan on about 50 minutes, with 8 exercises to check what you learned. Every example is real Go code: change it, run it again and compare the output, which is the fastest way to learn how each feature behaves.

Simple lesson: finish this chapter and you can handle names, notices, timetables and deadlines.

Lessons in this section

  1. Strings

    Create interpreted and raw strings, find the length, join, slice and compare text, use the strings package, understand runes, Unicode and UTF-8, and build text with strings.Builder.

    • Create interpreted and raw strings
    • Find the length, join, slice and compare strings
    • Search, split, join, replace, trim and change case with the strings package
    • Explain runes, Unicode and UTF-8, and count characters correctly
  2. Time and Date

    Work with time.Time and time.Duration: get the current time, build and parse dates, read their parts, add, subtract and compare times, and format them with Go's reference layout.

    • Explain time.Time and get the current time
    • Create dates with time.Date and time.Parse
    • Read the year, month, day, hour, minute and second
    • Add, subtract and compare times, and use durations