함수 duration to seconds

1 개요[ | ]

함수 duration to seconds

2 Java[ | ]

import java.time.Duration;
public class MyClass {
    public static void main(String args[]) {
      System.out.println( Duration.ofSeconds(3).getSeconds() );
      System.out.println( Duration.ofHours(3).getSeconds() );
      System.out.println( Duration.ofDays(1).getSeconds() );
      System.out.println( Duration.ofDays(31).getSeconds() );
      System.out.println( Duration.ofDays(365).getSeconds() );
    }
}

3 PHP[ | ]

<?php
function DateInterval2seconds($di) {
    return 1*DateTime::createFromFormat('U',0)->add($di)->format('U');
}
var_dump( DateInterval2seconds(new DateInterval('PT3S')) );
var_dump( DateInterval2seconds(new DateInterval('PT3H')) );
var_dump( DateInterval2seconds(new DateInterval('P1D')) );
var_dump( DateInterval2seconds(new DateInterval('P1M')) ); // = P31D
var_dump( DateInterval2seconds(new DateInterval('P1Y')) ); // = P365D
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}