- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要计算出某人有多少天了,但我不确定数学。这是我到目前为止所拥有的:
var birthYear = parseInt(prompt ('Enter your birth year:'));
var birthMonth = prompt ('Enter the name of the month of birth:');
var birthDay = parseInt(prompt ('Enter your day of birth as an integer:'));
var milliDay = 1000*60*60*24; //Milliseconds in a day
monthAbb = 'janfebmaraprmayjunjulaugsepoctnovdec';
chineseZod = 12;
zodCycle = 1924; //Chinese Zodiac Cycle
var zodAnimal = new Array('Rat','Ox','Tiger','Rabbit','Dragon','Snake','Horse','Goat','Monkey','Rooster','Dog','Pig');
var zodAnimalD = new Array('Forthright, tenacious, intense, meticulous, charismatic, sensitive, intellectual, industrious, charming, eloquent, sociable, artistic, and shrewd. Can be manipulative, vindictive, self-destructive, envious, mendacious, venal, obstinate, critical, over-ambitious, ruthless, intolerant, and scheming.','Dependable, ambitious, calm, methodical, born leader, patient, hardworking, conventional, steady, modest, logical, resolute, and tenacious. Can be stubborn, dogmatic, hot-tempered, narrow-minded, materialistic, rigid, and demanding.','Unpredictable, rebellious, colorful, powerful, passionate, daring, impulsive, vigorous, stimulating, sincere, affectionate, humanitarian, and generous. Can be restless, reckless, impatient, quick-tempered, obstinate, selfish, aggressive, and moody.','Gracious, good friend, kind, sensitive, soft-spoken, amiable, elegant, reserved, cautious, artistic, thorough, tender, self-assured, shy, astute, compassionate, lucky, and flexible. Can be moody, detached, superficial, self-indulgent, opportunistic, and stubborn.','Magnanimous, stately, vigorous, strong, self-assured, proud, noble, direct, dignified, eccentric, intellectual, fiery, passionate, decisive, pioneering, artistic, generous, and loyal. Can be tactless, arrogant, imperious, tyrannical, demanding, intolerant, dogmatic, violent, impetuous, and brash.','Deep thinker, wise, mystic, graceful, soft-spoken, sensual, creative, prudent, shrewd, elegant, cautious, responsible, calm, strong, constant, and purposeful. Can be a loner, bad communicator, possessive, hedonistic, self-doubting, distrustful, mendacious, suffocating, and cold.','Cheerful, popular, quick-witted, changeable, earthy, perceptive, talkative, agile, magnetic, intelligent, astute, flexible, and open-minded. Can be fickle, arrogant, childish, anxious, rude, gullible, and stubborn.','Righteous, sincere, sympathetic, mild-mannered, observant, artistic, intellectual, ingenious, innovative, creative, mothering, peaceful, and generous. Can be indecisive, over-passive, worrier, pessimistic, sensitive, shy, and weak-willed.','Inventor, motivator, improviser, quick-witted, inquisitive, flexible, innovative, problem solver, self-assured, sociable, artistic, polite, dignified, competitive, objective, and factual. Can be egotistical, vain, arrogant, selfish, reckless, snobbish, deceptive, manipulative, cunning, jealous, suspicious, and stubborn.',' Acute, neat, meticulous, organized, self-assured, decisive, conservative, critical, perfectionist, alert, zealous, practical, scientific, and responsible. Can be over zealous and critical, puritanical, egotistical, abrasive, proud, opinionated, and gives into empty bravado.','Honest, intelligent, straightforward, loyal, sense of justice and fair play, attractive, amicable, unpretentious, sociable, open-minded, idealistic, moralistic, practical, affectionate, sensitive, and easy going. Can be cynical, lazy, cold, judgmental, pessimistic, worrier, stubborn, and quarrelsome.','Honest, gallant, sturdy, sociable, peace-loving, patient, loyal, hard-working, trusting, sincere, calm, understanding, thoughtful, scrupulous, passionate, and intelligent. Can be naive, over-reliant, self-indulgent, gullible, fatalistic, and materialistic.');
var monthArr = new Array(11);
monthArr [0] = "jan";
monthArr [1] = "feb";
monthArr [2] = "mar";
monthArr [3] = "apr";
monthArr [4] = "may";
monthArr [5] = "jun";
monthArr [6] = "jul";
monthArr [7] = "aug";
monthArr [8] = "sep";
monthArr [9] = "oct";
monthArr [10] = "nov";
monthArr [11] = "dec";
var monthNum = monthAbb.indexOf(birthMonth.slice(0, 3).toLowerCase()) / 3;
alert(monthNum);
var d = new Date (birthYear, monthNum, birthDay);
alert(d);
var dCurrent = new Date();
dCurrent = dCurrent.getTime(); //Grabs the time of the current date in milliseconds.
var dTotal = dCurrent - d;
alert(dTotal);
dTotal = dTotal / milliDay;
dTotal = Math.floor(dTotal); //7193
alert(dTotal + ' is after division');
dTotal = dTotal / 365.25;
dTotal = Math.floor(dTotal);
alert(dTotal + ' is how old you are!');
dTotal = birthYear - zodCycle;
dTotal = dTotal % chineseZod;
alert(dTotal);
alert(d);
var testS;
testS = dCurrent - d;
testS = testS / milliDay;
testS = testS * 365.25;
document.write("<span style=\"color: red;\">" + 'Your birthday is ' + d.toDateString() + "</span>");
alert(testS);
最佳答案
这实际上比那容易得多。一旦你有了两个日期(他们的生日和“现在”),你只需执行以下操作:
var days = Math.floor((now - birthDate) / 86400000);
这是因为在 JavaScript 中,Date
objects自纪元以来以毫秒为单位的保持时间,当您对它们进行数学计算时,它们使用该毫秒值(结果是毫秒数)。 JavaScript 假设每天恰好有 86,400,000 毫秒。
因此,一旦您有了 birthYear
、monthNum
和 birthDay
:
var birthDate = new Date(birthYear, monthNum, birthDay);
var days = Math.floor((new Date() - birthdate) / 86400000);
关于javascript - 计算一个人的年龄有多少天?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9801487/
我正在从事一个项目,该项目要求我实现一种方法来确定工作日后一天的人的年龄;也就是每年九月的第一个星期一。 这个方法在以后的年份会用到,所以需要判断当前年份和劳动节后一天的人的年龄。 下面是我用来获取学
我已经在 Play 商店中部署了一个应用程序。我需要获取下载该应用程序的人的年龄 和性别。是否可以获取这些属性,或者我是否需要实现 Google Analytics 才能获取这些属性? 最佳答案 恐怕
我正在尝试根据出生日期计算年龄,我使用 this thread 成功地做到了这一点.但是,我的一些 DateOfBirth 具有空值,并且使用我下面的公式,结果返回为“2012”而不是(空白/空)。
我正在尝试根据财政年度结束时获取年龄。如果我的出生日期是 1962 年 1 月 16 日,那么我当前的年龄是 50 岁(假设今天的日期是 2012 年 1 月 16 日)。我可以使用什么 JavaSc
创建具有以下规范的函数: 函数名称:employee_matcher 目的:将员工姓名与提供的公司、年龄和性别相匹配 参数:公司(字符串)、年龄(整数)、性别(字符串) 返回:员工的名字和姓氏,如下所
1、根据身份证号码计算出生日期、年龄、性别(18位) 复制代码 代码如下: //获取输入身份证号码 var UUserCard = $("#UUserCard").val
适用于OA项目中这些对档案的管理 1、根据身份证号码计算出生日期、年龄、性别(18位) 复制代码代码如下: //获取输入身份证号码 var UUserCa
我将导入表中的数据INSERT INTO插入到我创建的新表中,该表包含有关人员、姓名、地址、出生日期、年龄、性别等的一般信息。 当我插入新表时,导入数据没有年龄,因此我在INSERT INTO之后执行
我如何使用 go standard 构建它? sql包让其他人可以阅读吗?我需要添加很多字段。 result, err := db.Exec( "INSERT INTO MyTable (na
是否有任何简单的 Android/Java 库/框架可以检测图片上的人脸并给我一些关于图片上的人的信息?我的意思是诸如性别、年龄、情绪(微笑、悲伤、愤怒)之类的信息...... 我试过Face++和微
我正在为我的 Android 应用程序使用 Firebase 身份验证。用户可以通过多个提供商(Google、Facebook、Twitter)登录。 成功登录后,有没有办法使用 Firebase a
我想知道是否可以用 PHP 以某种方式检查 session 时限。我浏览了 stackoverflow,但没有找到任何东西。提前感谢您的所有回答。 如果有人想知道为什么我需要知道这样的事情,我想在所有
我正在尝试使用 CakePHP 按出生日期分组并根据结果进行计数。这是我的查询。 $data = $this->User->find('all', array( 'fields' => arr
我正在尝试找出一种使用 Python 3.6 和 Boto 3 通过 aws lambda 函数让用户访问 key 年龄的方法。我的问题是我似乎无法找到正确的 api 调用(如果存在的话)以此目的。我
使用 Seaside 应用程序启动我的图像时,我在启动方法中有此代码: WAMySeasideApp>>startUp: resuming WAMySeasideApp waAppli
谷歌从哪里获得这些数据,是否有可能在没有它的情况下在我自己的网站上手动获得这些数据(假设它以某种Cookie /用户代理字符串/标识符/等形式存在)? 最佳答案 Google从第3方双击Cookie获
我在 Google App Engine 上部署了一个 Django 应用程序,该应用程序过早地将其用户注销。但是没有关闭浏览器窗口/选项卡。在 settings.py 中,我有以下代码: SESSI
我正在通过 Python 使用 YouTube API。我已经可以收集特定视频的所有评论,包括作者姓名、日期和评论内容。 我还可以使用单独的代码提取特定作者的个人信息(年龄、性别、兴趣……)。但我不能
print("how old are you") age = input(">") if age >= 24: print("you are getting old") print (age) els
我是一名优秀的程序员,十分优秀!