mramvq
Last Updated: February 25, 2016
·
1.13K
· wyuenho
Img 0675

How to get Jesus' birthday in Javascript

If you've never programmed a computer before 2000, you probably will be confused by this:

> new Date(1, 0, 1);
Tue Jan 01 1901 00:00:00 GMT+0800 (HKT)

Wha.. what? MDN's documentation says I can put the year as a number into the constructor and a JS Date can represent -100,000,000 days to 100,000,000 days relative to 01 January, 1970 UTC. Let's see here, 1970 * 365 = 719050 days, I can't possibly have 99280950 leaps days can I?

Problem

Javascript's Date constructor has to handle pre-Y2K years so the number between 0 to 99 is treated as if they represent the years 1900 - 1999.

Solution

> var d = new Date(1, 0, 1) // Put the date in as usual
> d.setFullYear(1) // Now you get Jesus' birthday.

Ah hum, Jesus was born on what? BC 6 - 4?

Say Thanks
Respond

3 Responses
Add your response

2004
Me 180x180

So, how old am I again?

over 1 year ago ·
2005
Img 0675

@jjperezaguinaga Don't know, depends on whether the labor process took 1 year or 2 years.

over 1 year ago ·
2006
Me 180x180

@wyuenho Assuming Maria got pregnant by deity overnight, you never know! I also wonder what triggered you to figure out this information.

over 1 year ago ·