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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:43:16+00:00 2026-06-05T13:43:16+00:00

I am currently coding a web page that allows users to change local settings

  • 0

I am currently coding a web page that allows users to change local settings on a singleboard embedded computer. A feature I am currently working on involves syncing the clock on the board with the clock on the user’s computer. The Javascript Date() function allows me to get the local machine’s time, so I am using that to get the current time.

My goal is to create a submit button that, when pressed, would grab the exact time from the javascript Date() function, and then use the POST method to return that time to my php code. The reason I need to POST the value is so that I can run a Linux command line program that has privileges to change the time setting of the board.

Right now, the board gets the time correctly and POSTs it correctly, but the issue I am having is that the time returned is the time at which the page was loaded, and not the time that the submit button was clicked.

This is an issue because if the user sits on the webpage for, let’s say, 5 minutes, and then clicks that button, the clock on the board will be submitted a time that is 5 minutes behind.

I have tried POSTing the value by assigning it to a hidden input item, which successfully posts it, but the time POSTed is the page load time. Another method I have tried was adding an onUnload call of a javascript function to the <body> tag, but the value does not seem to get POSTed when attempting to pass that time using the same method.

Here are the important code chunks that I am currently working with:

<?php
echo "<form method='POST' action='".$PHP_SELF."'>";

if (isset($_POST['getLocalTime']))
{
    echo $_POST['localTime'].'<br>';
    $setLocalTime = "My Commandline String";
    exec($setLocalTime);
}
?>

<input type="hidden" id="localTime" name="localTime">

<script language='JavaScript'>
var date = new Date();
var d = date.getUTCDate();
var day = (d < 10) ? '0' + d : d;
var m = date.getUTCMonth() + 1;
var month = (m < 10) ? '0' + m : m;
var year = date.getUTCFullYear();
var h = date.getUTCHours();
var hour = (h < 10) ? '0' + h : h;
var mi = date.getUTCMinutes();
var minute = (mi < 10) ? '0' + mi : mi;
var sc = date.getUTCSeconds();
var second = (sc < 10) ? '0' + sc : sc;
var loctime = month + day + hour + minute + year + "." + second;

document.getElementById('localTime').value = loctime;
</script>

<?php
echo "<pre>";
print_r($_POST);
echo "</pre>";
?>

<input class="button" type="submit" name="getLocalTime" value="Copy Local Time">
</form>

I appreciate any suggestions that can be given, and thanks in advance.

  • 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-05T13:43:17+00:00Added an answer on June 5, 2026 at 1:43 pm

    You should put your script in a function, and run that function using the onSubmit for the form object.

    In your form definition:

    echo "<form method='POST' action='".$PHP_SELF."' onsubmit='getTime();'>";
    

    And for the javascript:

    <script language='JavaScript'>
    function getTime(){
    var date = new Date();
    var d = date.getUTCDate();
    var day = (d < 10) ? '0' + d : d;
    var m = date.getUTCMonth() + 1;
    var month = (m < 10) ? '0' + m : m;
    var year = date.getUTCFullYear();
    var h = date.getUTCHours();
    var hour = (h < 10) ? '0' + h : h;
    var mi = date.getUTCMinutes();
    var minute = (mi < 10) ? '0' + mi : mi;
    var sc = date.getUTCSeconds();
    var second = (sc < 10) ? '0' + sc : sc;
    var loctime = month + day + hour + minute + year + "." + second;
    
    document.getElementById('localTime').value = loctime;
    }
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently, I have an asp.net web application that links to another page. The enduser
I'm currently working on an application that in addition to the usual visual web
I am currently trying to stream content out to the web after a trans-coding
I'm currently working at home, but it's not always an ideal environment for coding.
I have a web page that display this: The Html behind this is: <label>Approved
I am working on an ASP.NET 2.0 web solution which currently runs en-GB and
I am currently coding a HTML website into wordpress. The problem that i'm having
I am currently working on some prototypes for a web site I am wanting
We found that the performance of the current web page is very poor as
I need your opinion. I'm currently working on a web application, based on struts

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.