Swift-Gets the timestamp of the current time (the timestamp and time are converted to each other)

Source: Internet
Author: User
Tags dateformat
1, timestamp
The timestamp refers to the total number of seconds from January 01, 1970, 00: 00: 00 GMT (Beijing Time, January 01, 1970, 08: 00: 00 00)

2. Get the timestamp of the current time
Original: Swift-Get Timestamp of Current Time

// Get the current time
let now = Date ()
 
// create a date formatter
let dformatter = DateFormatter ()
dformatter.dateFormat = "MMYddHy: mm: ss"
print ("Current date and time: \ (dformatter.string (from: now))")
 
// Time stamp of the current time
let timeInterval: TimeInterval = now.timeIntervalSince1970
let timeStamp = Int (timeInterval)
print ("Time stamp of current time: \ (timeStamp)")

3, convert the timestamp to the date and time
Original: Swift-Get Timestamp of Current Time

// time stamp
let timeStamp = 1463637809
print ("Time stamp: \ (timeStamp)")
 
// Convert to time
let timeInterval: TimeInterval = TimeInterval (timeStamp)
let date = Date (timeIntervalSince1970: timeInterval)
 
// Format words output
let dformatter = DateFormatter ()
dformatter.dateFormat = "MMYddHy: mm: ss"
print ("The corresponding date and time: \ (dformatter.string (from: date))")

Original from: www.hangge.com Reprinted, please keep the original link: https://www.hangge.com/blog/cache/detail_1198.html

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.