Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7637961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:03:42+00:00 2026-05-31T08:03:42+00:00

This morning I noticed a peculiar issue with the JavaScript setFullYear method. When using

  • 0

This morning I noticed a peculiar issue with the JavaScript setFullYear method.

When using the method like so:

d.setFullYear(2012,2,8);

The correct value is returned:

Thu Mar 08 2012 10:30:04 GMT+0000 (GMT Standard Time)

However if I use the parseInt method to return the integers, the date returned is incorrect:

d.setFullYear(parseInt("2012"), parseInt("02"), parseInt("08"));

returns:

Wed Feb 29 2012 10:31:30 GMT+0000 (GMT Standard Time)

It appears that the parseInt method is returning the incorrect values, but when I test it:

document.write(parseInt("2"));

Then the correct value is returned (2)

A working fiddle is here: http://jsfiddle.net/rXByJ/

Does the problem lie with parseInt or with setFullYear?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T08:03:44+00:00Added an answer on May 31, 2026 at 8:03 am

    The problem is that parseInt('08') is 0. This works:

    d.setFullYear(parseInt("2012"), parseInt("02"), 8);
    

    Both parseInt(’08’) and parseInt(’09’) return zero because the
    function tries to determine the correct base for the numerical system
    used. In Javascript numbers starting with zero are considered octal
    and there’s no 08 or 09 in octal, hence the problem.

    http://www.ventanazul.com/webzine/articles/issues-parseint-javascript

    Solution is to use the second parameter:

    parseInt('08', 10) 
    

    Or

    Number('08')
    

    Also see How do I work around JavaScript's parseInt octal behavior?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Whilst working on some generally horrible Javascript code this morning, I came across the
Launched Eclipse Indigo on Windows XP SP3 this morning and noticed it was taking
I was writing some practice programs for my java certification this morning, and noticed
hi i have put this together this morning for a friend using MVC he
This morning I stumbled over a weird issue in Visual Studio's Windows Forms designer.
This morning I noticed that some results to our website have been poisoned in
I was looking at an Ant build.xml file this morning and noticed an XML
This morning I had a look at my blog on my iPhone and noticed
I noticed some 404's in my logs this morning so I took a look
Yesterday morning I noticed Google Search was using hash parameters: http://www.google.com/#q=Client-side+URL+parameters which seems to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.