DateComponentsFormatter获取时间格式为1y 1m 1d 2h 1min in swift

时间:2016-12-26 06:12:56

标签: swift nsdatecomponentsformatter

func calculateTimeUsingFormatter(seconds : Int) -> String
{
    let formatter = DateComponentsFormatter()
    formatter.unitsStyle = .abbreviated
    formatter.zeroFormattingBehavior = .pad
    formatter.allowedUnits = [.year, .month , .day, .hour , .minute]

    let minutes1 = seconds / 60
    let timeInterval = TimeInterval(minutes1 * 60)
    return formatter.string(from: timeInterval)!
}

我输入了:

24 * 395 * 60 * 60 + 48 * 60 * 60 + 60 + 60 * 60 + 31 + 60 * 60 

然后我输出了一个输出:

1y 1m 1d 2h 1m 

但我需要一个实际的输出:

1y 1m 1d 2h 1min 

你能帮我吗?

0 个答案:

没有答案