| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- //
- // News.swift
- // Sirani
- //
- // Created by Anhar Solehudin on 06/04/19.
- // Copyright © 2019 Anhar Solehudin. All rights reserved.
- //
- import Foundation
- struct News {
- private(set) public var id: Int
- private(set) public var title_news: String
- private(set) public var pra_news: String
- private(set) public var create_date: String
-
- init (id: Int, title_news: String, pra_news: String, create_date: String) {
- self.id = id
- self.title_news = title_news
- self.pra_news = pra_news
- self.create_date = create_date
- }
-
- func date() -> String {
- var date = ""
-
- if (create_date == "null" || create_date.isEmpty) {
- date = ""
- } else {
- let createdDate = create_date.prefix(10)
- let inputFormatter = DateFormatter()
- inputFormatter.dateFormat = "yyyy-MM-dd"
- let dateString = String(createdDate)
-
- if let output = inputFormatter.date(from: dateString) {
- let outputFormatter = DateFormatter()
- outputFormatter.dateFormat = "dd-MM-yyyy"
- date = outputFormatter.string(from: output)
- }
- }
-
- return date
- }
- }
|