...
Blogios App DevelopmentExploring Formatters in Swift

Exploring Formatters in Swift

import Foundation

let dateFormatter = DateFormatter()
dateFormatter.dateStyle = .medium
dateFormatter.timeStyle = .short
let currentDate = Date()
let dateString = dateFormatter.string(from: currentDate)
print(dateString) // Example: "Aug 5, 2024 at 3:45 PM"
 
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
let customDateString = dateFormatter.string(from: currentDate)
print(customDateString) // Example: "2024-08-05 15:45:00"
let numberFormatter = NumberFormatter()
numberFormatter.numberStyle = .currency
numberFormatter.locale = Locale(identifier: "en_US")
let price = 1234.56
let priceString = numberFormatter.string(from: NSNumber(value: price))
print(priceString) // Example: "$1,234.56"

MeasurementFormatter

let numberFormatter = NumberFormatter()
numberFormatter.numberStyle = .currency
numberFormatter.locale = Locale(identifier: "en_US")
let price = 1234.56
let priceString = numberFormatter.string(from: NSNumber(value: price))
print(priceString) // Example: "$1,234.56"

ByteCountFormatter

ISO8601DateFormatter

Usage

PersonNameComponentsFormatter

Usage

DateIntervalFormatter

Usage

DateComponentsFormatter

Usage

Conclusion



Creating digital solutions for your business

Subscribe

Subscribe to stay updated with our latest Tech News & Blogs

Copyright Synclovis System Pvt. Ltd. © 2024. All Rights Reserved