19
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

誕生日年齢計算

Posted at

誕生日から年齢を計算します。

PHPで書く場合です。

birthday.php
<?php
 $now = date("Ymd"); 
 $birth = "19800901"; 
 echo floor(($now-$birth)/10000);
?>

Flex SDKに含まれるDateFormatterを利用する場合です。

birthday4flex.mxml
import mx.formatters.DateFormatter; 
var date_fmt:DateFormatter = new DateFormatter(); 
date_fmt.formatString = "YYYYMMDD"; 
var now:Number = Number(date_fmt.format(new Date())); 
var birth:Number = 19800901; 
trace(Math.floor((now-birth)/10000));

ActionScript3.0で書く場合です。

birthday4as.as
var date:Date = new Date(); 
var now:Number = date.getFullYear() + (date.getMonth()+1) * 100 + date.Date(); 
var birth:Number = 19800901; 
trace(Math.floor((now-birth)/10000));

この記事は、以前ブログで公開していた記事、内容を再編集したものです。
ActionScript 1.0/2.0/3.0とFlex 3の内容が中心です。

19
16
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
19
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?