Skip to content

Instantly share code, notes, and snippets.

@amosgyamfi
Created August 5, 2020 12:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amosgyamfi/3fc6ac4506e32d861dfc94d27f9b4253 to your computer and use it in GitHub Desktop.
Save amosgyamfi/3fc6ac4506e32d861dfc94d27f9b4253 to your computer and use it in GitHub Desktop.
//
// ContentView.swift
// dateInterval
//
// Created by Amos Gyamfi on 2.8.2020.
//
import SwiftUI
struct ContentView: View {
var body: some View {
VStack(alignment: .leading, spacing: 20) {
Text("Date and Time in SwiftUI")
.font(/*@START_MENU_TOKEN@*/.title/*@END_MENU_TOKEN@*/)
Spacer()
// 4 hour Range
Text("4 hour range: ").font(.system(.headline)).foregroundColor(Color(.systemBlue)) + Text(Date()...Date().addingTimeInterval(3600*4))
// Today's date
Text("Today's date: ").font(.system(.headline)).foregroundColor(Color(.systemBlue)) + Text(Date().addingTimeInterval(600), style: .date)
// Current time
Text("Current time: ").font(.system(.headline)).foregroundColor(Color(.systemBlue)) + Text(Date().addingTimeInterval(600), style: .time)
// Counter: relative countdown timer
Text("Relative: ").font(.system(.headline)).foregroundColor(Color(.systemBlue)) + Text(Date().addingTimeInterval(600), style: .relative)
// Counter: Regular 30 minutes countdown timer
Text("Regular: ").font(.system(.headline)).foregroundColor(Color(.systemBlue)) + Text(Date().addingTimeInterval(1800), style: .timer)
}.padding(.vertical, 300)
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
.preferredColorScheme(/*@START_MENU_TOKEN@*/.dark/*@END_MENU_TOKEN@*/)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment