-
-
Save billwang1990/b9b085698bcc03a8212557ab60a5903f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// TraditionalTime.swift | |
// iOS-Startup | |
// | |
// Created by Yaqing Wang on 4/24/17. | |
// Copyright © 2017 Yaqing Wang. All rights reserved. | |
// | |
import Foundation | |
struct TraditionalTime { | |
static func currentTranditionalTime() -> String { | |
let date = Date() | |
print(date) | |
let formatter = DateFormatter() | |
formatter.dateFormat = "yyyy-MM-dd HH:mm" | |
let prefixFormatter = DateFormatter() | |
prefixFormatter.dateFormat = "yyyy-MM-dd " | |
for var timeObj in timeMappings { | |
if let start = timeObj["start"], let end = timeObj["end"] { | |
let startTime = formatter.date(from: prefixFormatter.string(from: date) + start)! | |
let endTime = formatter.date(from: prefixFormatter.string(from: date) + end)! | |
if date >= startTime && date < endTime { | |
return timeObj["desc"] ?? "未知" | |
} | |
} | |
} | |
return "未知" | |
} | |
static let timeMappings: [[String: String]] = [ | |
[ | |
"desc": "子正一刻", | |
"start": "00:00", | |
"end": "00:15" | |
], | |
[ | |
"desc": "子正二刻", | |
"start": "00:15", | |
"end": "00:30" | |
], | |
[ | |
"desc": "子正三刻", | |
"start": "00:30", | |
"end": "00:45" | |
], | |
[ | |
"desc": "子正四刻", | |
"start": "00:45", | |
"end": "01:00" | |
], | |
[ | |
"desc": "丑初一刻", | |
"start": "01:00", | |
"end": "01:15" | |
], | |
[ | |
"desc": "丑初二刻", | |
"start": "01:15", | |
"end": "01:30" | |
], | |
[ | |
"desc": "丑初三刻", | |
"start": "01:30", | |
"end": "01:45" | |
], | |
[ | |
"desc": "丑初四刻", | |
"start": "01:45", | |
"end": "02:00" | |
], | |
[ | |
"desc": "丑正一刻", | |
"start": "02:00", | |
"end": "02:15" | |
], | |
[ | |
"desc": "丑正二刻", | |
"start": "02:15", | |
"end": "02:30" | |
], | |
[ | |
"desc": "丑正三刻", | |
"start": "02:30", | |
"end": "02:45" | |
], | |
[ | |
"desc": "丑正四刻", | |
"start": "02:45", | |
"end": "03:00" | |
], | |
[ | |
"desc": "寅初一刻", | |
"start": "03:00", | |
"end": "03:15" | |
], | |
[ | |
"desc": "寅初二刻", | |
"start": "03:15", | |
"end": "03:30" | |
], | |
[ | |
"desc": "寅初三刻", | |
"start": "03:30", | |
"end": "03:45" | |
], | |
[ | |
"desc": "寅初四刻", | |
"start": "03:45", | |
"end": "04:00" | |
], | |
[ | |
"desc": "寅正一刻", | |
"start": "04:00", | |
"end": "04:15" | |
], | |
[ | |
"desc": "寅正二刻", | |
"start": "04:15", | |
"end": "04:30" | |
], | |
[ | |
"desc": "寅正三刻", | |
"start": "04:30", | |
"end": "04:45" | |
], | |
[ | |
"desc": "寅正四刻", | |
"start": "04:45", | |
"end": "05:00" | |
], | |
[ | |
"desc": "卯初一刻", | |
"start": "05:00", | |
"end": "05:15" | |
], | |
[ | |
"desc": "卯初二刻", | |
"start": "05:15", | |
"end": "05:30" | |
], | |
[ | |
"desc": "卯初三刻", | |
"start": "05:30", | |
"end": "05:45" | |
], | |
[ | |
"desc": "卯初四刻", | |
"start": "05:45", | |
"end": "06:00" | |
], | |
[ | |
"desc": "卯正一刻", | |
"start": "06:00", | |
"end": "06:15" | |
], | |
[ | |
"desc": "卯正二刻", | |
"start": "06:15", | |
"end": "06:30" | |
], | |
[ | |
"desc": "卯正三刻", | |
"start": "06:30", | |
"end": "06:45" | |
], | |
[ | |
"desc": "卯正四刻", | |
"start": "06:45", | |
"end": "07:00" | |
], | |
[ | |
"desc": "辰初一刻", | |
"start": "07:00", | |
"end": "07:15" | |
], | |
[ | |
"desc": "辰初二刻", | |
"start": "07:15", | |
"end": "07:30" | |
], | |
[ | |
"desc": "辰初三刻", | |
"start": "07:30", | |
"end": "07:45" | |
], | |
[ | |
"desc": "辰初四刻", | |
"start": "07:45", | |
"end": "08:00" | |
], | |
[ | |
"desc": "辰正一刻", | |
"start": "08:00", | |
"end": "08:15" | |
], | |
[ | |
"desc": "辰正二刻", | |
"start": "08:15", | |
"end": "08:30" | |
], | |
[ | |
"desc": "辰正三刻", | |
"start": "08:30", | |
"end": "08:45" | |
], | |
[ | |
"desc": "辰正四刻", | |
"start": "08:45", | |
"end": "09:00" | |
], | |
[ | |
"desc": "巳初一刻", | |
"start": "09:00", | |
"end": "09:15" | |
], | |
[ | |
"desc": "巳初二刻", | |
"start": "09:15", | |
"end": "09:30" | |
], | |
[ | |
"desc": "巳初三刻", | |
"start": "09:30", | |
"end": "09:45" | |
], | |
[ | |
"desc": "巳初四刻", | |
"start": "09:45", | |
"end": "10:00" | |
], | |
[ | |
"desc": "巳正一刻", | |
"start": "10:00", | |
"end": "10:15" | |
], | |
[ | |
"desc": "巳正二刻", | |
"start": "10:15", | |
"end": "10:30" | |
], | |
[ | |
"desc": "巳正三刻", | |
"start": "10:30", | |
"end": "10:45" | |
], | |
[ | |
"desc": "巳正四刻", | |
"start": "10:45", | |
"end": "11:00" | |
], | |
[ | |
"desc": "午初一刻", | |
"start": "11:00", | |
"end": "11:15" | |
], | |
[ | |
"desc": "午初二刻", | |
"start": "11:15", | |
"end": "11:30" | |
], | |
[ | |
"desc": "午初三刻", | |
"start": "11:30", | |
"end": "11:45" | |
], | |
[ | |
"desc": "午初四刻", | |
"start": "11:45", | |
"end": "12:00" | |
], | |
[ | |
"desc": "午正一刻", | |
"start": "12:00", | |
"end": "12:15" | |
], | |
[ | |
"desc": "午正二刻", | |
"start": "12:15", | |
"end": "12:30" | |
], | |
[ | |
"desc": "午正三刻", | |
"start": "12:30", | |
"end": "12:45" | |
], | |
[ | |
"desc": "午正四刻", | |
"start": "12:45", | |
"end": "13:00" | |
], | |
[ | |
"desc": "未初一刻", | |
"start": "13:00", | |
"end": "13:15" | |
], | |
[ | |
"desc": "未初二刻", | |
"start": "13:15", | |
"end": "13:30" | |
], | |
[ | |
"desc": "未初三刻", | |
"start": "13:30", | |
"end": "13:45" | |
], | |
[ | |
"desc": "未初四刻", | |
"start": "13:45", | |
"end": "14:00" | |
], | |
[ | |
"desc": "未正一刻", | |
"start": "14:00", | |
"end": "14:15" | |
], | |
[ | |
"desc": "未正二刻", | |
"start": "14:15", | |
"end": "14:30" | |
], | |
[ | |
"desc": "未正三刻", | |
"start": "14:30", | |
"end": "14:45" | |
], | |
[ | |
"desc": "未正四刻", | |
"start": "14:45", | |
"end": "15:00" | |
], | |
[ | |
"desc": "申初一刻", | |
"start": "15:00", | |
"end": "14:15" | |
], | |
[ | |
"desc": "申初二刻", | |
"start": "15:15", | |
"end": "15:30" | |
], | |
[ | |
"desc": "申初三刻", | |
"start": "15:30", | |
"end": "15:45" | |
], | |
[ | |
"desc": "申初四刻", | |
"start": "15:45", | |
"end": "16:00" | |
], | |
[ | |
"desc": "申正一刻", | |
"start": "16:00", | |
"end": "16:15" | |
], | |
[ | |
"desc": "申正二刻", | |
"start": "16:15", | |
"end": "16:30" | |
], | |
[ | |
"desc": "申正三刻", | |
"start": "16:30", | |
"end": "16:45" | |
], | |
[ | |
"desc": "申正四刻", | |
"start": "16:45", | |
"end": "17:00" | |
], | |
[ | |
"desc": "酉初一刻", | |
"start": "17:00", | |
"end": "17:15" | |
], | |
[ | |
"desc": "酉初二刻", | |
"start": "17:15", | |
"end": "17:30" | |
], | |
[ | |
"desc": "酉初三刻", | |
"start": "17:30", | |
"end": "17:45" | |
], | |
[ | |
"desc": "酉初四刻", | |
"start": "17:45", | |
"end": "18:00" | |
], | |
[ | |
"desc": "酉正一刻", | |
"start": "18:00", | |
"end": "18:15" | |
], | |
[ | |
"desc": "酉正二刻", | |
"start": "18:15", | |
"end": "18:30" | |
], | |
[ | |
"desc": "酉正三刻", | |
"start": "18:30", | |
"end": "18:45" | |
], | |
[ | |
"desc": "酉正四刻", | |
"start": "18:45", | |
"end": "19:00" | |
], | |
[ | |
"desc": "戌初一刻", | |
"start": "19:00", | |
"end": "19:15" | |
], | |
[ | |
"desc": "戌初二刻", | |
"start": "19:15", | |
"end": "19:30" | |
], | |
[ | |
"desc": "戌初三刻", | |
"start": "19:30", | |
"end": "19:45" | |
], | |
[ | |
"desc": "戌初四刻", | |
"start": "19:45", | |
"end": "20:00" | |
], | |
[ | |
"desc": "戌正一刻", | |
"start": "20:00", | |
"end": "20:15" | |
], | |
[ | |
"desc": "戌正二刻", | |
"start": "20:15", | |
"end": "20:30" | |
], | |
[ | |
"desc": "戌正三刻", | |
"start": "20:30", | |
"end": "20:45" | |
], | |
[ | |
"desc": "戌正四刻", | |
"start": "20:45", | |
"end": "21:00" | |
], | |
[ | |
"desc": "亥初一刻", | |
"start": "21:00", | |
"end": "21:15" | |
], | |
[ | |
"desc": "亥初二刻", | |
"start": "21:15", | |
"end": "21:30" | |
], | |
[ | |
"desc": "亥初三刻", | |
"start": "21:30", | |
"end": "21:45" | |
], | |
[ | |
"desc": "亥初四刻", | |
"start": "21:45", | |
"end": "22:00" | |
], | |
[ | |
"desc": "亥正一刻", | |
"start": "22:00", | |
"end": "22:15" | |
], | |
[ | |
"desc": "亥正二刻", | |
"start": "22:15", | |
"end": "22:30" | |
], | |
[ | |
"desc": "亥正三刻", | |
"start": "22:30", | |
"end": "22:45" | |
], | |
[ | |
"desc": "亥正四刻", | |
"start": "22:45", | |
"end": "23:00" | |
], | |
[ | |
"desc": "子初一刻", | |
"start": "23:00", | |
"end": "23:15" | |
], | |
[ | |
"desc": "子初二刻", | |
"start": "23:15", | |
"end": "23:30" | |
], | |
[ | |
"desc": "子初三刻", | |
"start": "23:30", | |
"end": "23:45" | |
], | |
[ | |
"desc": "子初四刻", | |
"start": "23:45", | |
"end": "23:59" | |
] | |
] | |
} | |
let 时辰 = TraditionalTime.currentTranditionalTime() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment