Here you can find the source of formatISO8601Duration(int[] t)
Parameter | Description |
---|---|
t | 6 or 7-element array with [year,mon,day,hour,min,sec,nanos] |
public static String formatISO8601Duration(int[] t)
//package com.java2s; /*/*w w w . j ava 2 s . c om*/ * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ public class Main { /** * format ISO8601 duration string, for example [1,0,0,1,0,0,0] → P1YT1H * @param t 6 or 7-element array with [year,mon,day,hour,min,sec,nanos] * @return the formatted ISO8601 duration */ public static String formatISO8601Duration(int[] t) { StringBuilder result = new StringBuilder(24); result.append('P'); if (t[0] != 0) result.append(t[0]).append('Y'); if (t[1] != 0) result.append(t[1]).append('M'); if (t[2] != 0) result.append(t[2]).append('D'); if (t[3] != 0 || t[4] != 0 || t[5] != 0 || (t.length == 7 && t[6] != 0)) { result.append('T'); if (t[3] != 0) result.append(t[3]).append('H'); if (t[4] != 0) result.append(t[4]).append('M'); if (t[5] != 0 || (t.length == 7 && t[6] != 0)) { if (t.length < 7 || t[6] == 0) { result.append(t[5]).append('S'); } else { double sec = t[5] + t[6] / 1000000000.; result.append(sec).append('S'); } } } return result.toString(); } }