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 8472343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:02:36+00:00 2026-06-10T17:02:36+00:00

Ok, Im trying to convert a javascript timestamp to a php equivalent, I have

  • 0

Ok, Im trying to convert a javascript timestamp to a php equivalent, I have surfed the posts here on stack for a decent answer as well as various other sites so this question comes as a last ditch effort despite knowing Im likely to get down votes, and someone telling me nothing more than this is a dupe question from somewhere else. So despite that..

This is my failure of an attempt thus far. Please Note I am using jQuery, with noConflict hence the j rather than the $

var yr = j('#time_year :selected').val();//year
var mn = j('#time_month :selected').val();//month
var dy = j('#time_day :selected').val();//day
var hr = j('#time_hour :selected').val();//hour
var min = j('#time_minute :selected').val();//minute
var sc = j('#time_second :selected').val();//second

if(j('#time_ampm :selected').val() == 12 && j('#time_hour :selected').val() < 12){hr = j('#time_hour :selected').val()+12;}
if(j('#time_ampm :selected').val() == 0 && j('#time_hour :selected').val() == 12){hr = 0;}

var theDate = new Date(yr, mn, dy, hr, min, sc).getTime();
setTimeStamps(theDate);
j('#timestamp_now_js').html(" "+theTime);
j('#timestamp_now_php').html(" "+Math.round(theTime / 1000));

The select values at the top are based off of Mozilla.org Date reference using 0-nn as they describe. Where as the am/pm if-else is essentially meant to add 12 hours to the time selected as the time displayed on the site is 12-hour format. Javascript uses 24-hour. Its also there in the event that if am is picked and the use 12 it will convert 12 to 0 to match the 24-hour formatting concept.

Currently what appears to be happening is that despite it seeming to work, when I run the timestamp given through a php date() function it shows a date thats about a month 2 weeks and a few days a head of what I am testing off of, which is the equivalent of now

I would create a jsFiddle of the whole thing html included, but I use php through out to generate my select boxes. So with that if you want to see what I have “live” then go to http://7pz.net/timestamps.php as thats where I am testing the concept.

  • 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-06-10T17:02:37+00:00Added an answer on June 10, 2026 at 5:02 pm

    That’s because in Javascript’s Date objects the month range is 0-11, not 1-12. That’s for the “month” part. Try this:

    var mn = j('#time_month :selected').val() - 1; //month
    

    Or better, generate the <option>s with values ranging from 0 to 11.

    Plus, this statement:

    hr = j('#time_hour :selected').val()+12;
    

    Remember that j('#time_hour :selected').val() is a string, not a number, so you have to convert it before adding 12, or else you’d get something like "0412". You’re creating a date with the hour count set to 412, i.e. 17 days and 4 hours. And 17 days are addes to the day count.

    Fix it like this:

    hr = +j('#time_hour :selected').val() + 12;
    

    I used the plus unary operator.

    (P.S.: there’s a lot of room to improve your code, starting with readability and jQuery object caching. Take some time improving your Javascript coding skills before getting used to some bad practices.)

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

Sidebar

Related Questions

I'm trying to convert a timestamp string to Date in PHP. I have following
I have a piece of Javascript code and i am trying to convert it
Im trying to convert this php function to javascript: function sanitize_words($string,$limit=false) { preg_match_all(/\p{L}[\p{L}\p{Mn}\p{Pd}'\x{2019}]{1,}/u,$string,$matches,PREG_PATTERN_ORDER); return
I'm trying to convert this piece of JavaScript which sets a callback in PHP
I have an unsigned long in javascript that I'm trying to convert to a
I was trying to convert basic Javascript function into PHP, and I saw that
I am trying to convert my jQuery script into javascript. I have a problem
I am new to PHP and I'm trying to convert a simple Javascript function
Background : I'm trying to convert some JavaScript code which uses the the Crossfilter
I am trying to convert some pre-existing html/JavaScript files to Flex. I tried making

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.