I have in my company desktop software that receives information from text files (txt) generated by a web page in php
. However, I have to make the software read (in real time) the date and time of the system, and each information must be generated in a different file. I was able to php
generate the date and time according to the click of a button on the page, but I needed the time to be updated in real time so the program could display correctly.
Is there a function that passes and updates a txt file with the current time? We can use php
, js
, ajax
, jquery
or any other alternative.
Another option would be to create a xml
file that would receive the current system time in real time, but I have no idea how to do it.
Follow the code used to save the date and time in the files:
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="utf-8">
<title>Gestão para OBS</title>
</head>
<body>
<form action="index.php" method="post">
<input type="submit" value="Data" name="btnBotao">
<input type="submit" value="Hora" name="btnBotao">
</form>
</body>
<?php
$botao = $_POST["btnBotao"];
switch($botao)
{
case 'Data':
date_default_timezone_set('America/Sao_Paulo');
$data = date("d/m/Y");
$arquivo_data = "Data.txt";
$fo = fopen($arquivo_data, "w+");
fwrite($fo, $data);
fclose($fo);
break;
case 'Hora':
date_default_timezone_set('America/Sao_Paulo');
$hora = date("H:i");
$arquivo_hora = "Hora.txt";
$fo = fopen($arquivo_hora, "w+");
fwrite($fo, $hora);
fclose($fo);
break;
}
?>
</html>
The program generates the files Data.txt
and Hora.txt
, but the time needs to be updated in real time.