함수 duration to seconds

Jmnote (토론 | 기여)님의 2021년 8월 22일 (일) 15:42 판 (→‎PHP)

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')) );
var_dump( DateInterval2seconds(new DateInterval('P1Y')) );
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}