Forráskód Böngészése

1.修改时间显示

wenweiwei 3 éve
szülő
commit
d467152dd2
1 módosított fájl, 12 hozzáadás és 2 törlés
  1. 12 2
      BFCommonKit/Classes/BFUtility/PQCommonMethodUtil.swift

+ 12 - 2
BFCommonKit/Classes/BFUtility/PQCommonMethodUtil.swift

@@ -696,8 +696,18 @@ public func updateTimeToCurrenTime(timeInterval: TimeInterval) -> String {
     let date = NSDate(timeIntervalSince1970: timeInterval)
     let dfmatter = DateFormatter()
     // yyyy-MM-dd HH:mm:ss
-    dfmatter.dateFormat = "M月d日"
-    return dfmatter.string(from: date as Date)
+    dfmatter.dateFormat = "yyyy年M月d日"
+    
+    var dfmatterStr = dfmatter.string(from: date as Date)
+    
+    let currentDF = DateFormatter()
+    // yyyy-MM-dd HH:mm:ss
+    currentDF.dateFormat = "yyyy"
+    let currentDFStr = currentDF.string(from: Date())
+    if dfmatterStr.hasPrefix(currentDFStr) {
+        dfmatterStr.removeFirst(currentDFStr.count + 1)
+    }
+    return dfmatterStr
 }
 
 /// 判断字符串或者字典是否为空