好的,所以我想显示转换为用户设备时区的服务器时间
使用以下方法在firebase数据库中保存日期:
firebase.database.ServerValue.TIMESTAMP
即时使用moment.js将其转换为使用此代码的用户设备
timezone="Europe/London"; //get device time zone with corddova later
var date = moment.tz(snapshot3.val().date, timezone).format("MM-DD-YYYY HH:mm");
如您所见,这需要设备的时区名称,我如何使用cordova / Phonegap获取它?
答案 0 :(得分:0)
好吧我解决了这个问题,我放弃了geting设备的时区名称,我只是使用了moment.js函数
let dividend = NSDecimalNumber(string: Price)
let divisor = NSDecimalNumber(decimal: 0.05)
let quotient: NSDecimalNumber? = dividend.dividing(by: divisor, withBehavior: NSDecimalNumberHandler(roundingMode: .down, scale: 0, raiseOnExactness: false, raiseOnOverflow: false, raiseOnUnderflow: false, raiseOnDivideByZero: false))
let subtractAmount: NSDecimalNumber? = quotient?.multiplying(by: divisor)
var remainder: NSDecimalNumber? = nil
if let anAmount = subtractAmount {
remainder = dividend.subtracting(anAmount)
}