使用 Flex 计算年龄的最佳方法是什么? [英] What is the best way to calculate Age using Flex?

查看:36
本文介绍了使用 Flex 计算年龄的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Flex 计算年龄的最佳方法是什么?

解决方案

我在 本页底部的评论部分(现已离线).

<块引用>

jpwrunyan 于 2007 年 4 月 30 日晚上 10:10 说:

<块引用>

顺便说一下,这里是如何从 DOB 计算年龄(仅)而不需要考虑闰年:

通过Fine-Wei Lin稍加修正,代码读取

私有函数 getYearsOld(dob:Date):uint {var now:Date = new Date();var yearsOld:uint = Number(now.fullYear) - Number(dob.fullYear);if (dob.month > now.month || (dob.month == now.month && dob.date > now.date)){岁--;}回归岁数;}

<块引用><块引用>

这可以处理您需要计算年龄的大多数情况.

What is the best way to calculate Age using Flex?

解决方案

I found an answer at the bottom of this page in comments section (which is now offline).

jpwrunyan said on Apr 30, 2007 at 10:10 PM :

By the way, here is how to calculate age in years (only) from DOB without needing to account for leap years:

With a slight correction by Fine-Wei Lin, the code reads

private function getYearsOld(dob:Date):uint {  
    var now:Date = new Date();  
    var yearsOld:uint = Number(now.fullYear) - Number(dob.fullYear);  
    if (dob.month > now.month || (dob.month == now.month && dob.date > now.date)) 
    {
       yearsOld--;
    }
    return yearsOld;  
}

This handles most situations where you need to calculate age.

这篇关于使用 Flex 计算年龄的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆