Jump to content

Recommended Posts

Hello,

I am trying to convert the  Date,Month,Year, Hour:Minutes:Seconds  to Timestamp  and Timestamp  to Date,Month,Year, Hour:Minutes:Seconds .

 

I ve setted the Timezone as Asia/Calcutta in the code .

 

The Code works well when I run in my localhost , But when I run the code in my server located in Dallas,TX,USA the data changes largely .

For example :

The Timestamp generated for 24-May-2014 00:00:00 is 1400889600 in my localhost (Chennai, India).

The Timestamp generated for 24-May-2014 00:00:00 is 1400914800 in my server (Dallas, TX, USA).

 

why this changes occurs even though I ve setted the timezone ?

 

Code:

<?php
$date = new DateTime(null, new DateTimeZone('Asia/Calcutta'));
$ist = ($date->getTimestamp() + $date->getOffset());
echo "<h1>Current Timestamp and Date and Time for India</h1> <b>".$ist.'</b>';echo "     ";echo '<b>'.date('D, d M Y H:i:s ',$ist).'+0530</b>';
echo "<br />";
?>
<h1>Timestamp to Date and Time Converter</h1>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="number" name="timestamp_to_dt_timestamp" id="timestamp_to_dt_timestamp" />
<input type="submit" id="submit" name="submit" value="Submit" />
</form>
<?php 
if (isset($_POST['timestamp_to_dt_timestamp'])) {
$timestamp_to_dt_timestamp = $_POST['timestamp_to_dt_timestamp'];
echo 'Date and Time for the Timestamp :'.$timestamp_to_dt_timestamp.' is : '.date('D, d M Y H:i:s ',$timestamp_to_dt_timestamp);
}
?>
<h1>Date and Time to TimeStamp Converter</h1>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
Date (no preceeding zeros):  <input type="text" name="dt_to_timestamp__date" id="dt_to_timestamp__date" value="<?php echo date('j',$ist) ?>" /><br />
Month (number): <input type="text" name="dt_to_timestamp__month" id="dt_to_timestamp__month" value="<?php echo date('n',$ist) ?>" /><br />
Year : <input type="text" name="dt_to_timestamp__year" id="dt_to_timestamp__year" value="<?php echo date('Y',$ist) ?>" /><br />
Hours : <input type="text" name="dt_to_timestamp__hours" id="dt_to_timestamp__hours" value="00" /><br />
Minutes : <input type="text" name="dt_to_timestamp__mins" id="dt_to_timestamp__mins" value="00" /><br />
Seconds : <input type="text" name="dt_to_timestamp__sec" id="dt_to_timestamp__sec" value="00" /><br />
<input type="submit" id="submit" name="submit" value="Submit" />
<p>Leave the time field(s) if you don't know the exact time.</p>
</form>
<?php


if (isset($_POST['dt_to_timestamp__date'])) {
$dt_to_timestamp__date = $_POST['dt_to_timestamp__date'];
}
if (isset($_POST['dt_to_timestamp__month'])) {
$dt_to_timestamp__month = $_POST['dt_to_timestamp__month'];
}
if (isset($_POST['dt_to_timestamp__year'])) {
$dt_to_timestamp__year = $_POST['dt_to_timestamp__year'];
}
if (isset($_POST['dt_to_timestamp__hours'])) {
$dt_to_timestamp__hours = $_POST['dt_to_timestamp__hours'];
}
if (isset($_POST['dt_to_timestamp__mins'])) {
$dt_to_timestamp__mins = $_POST['dt_to_timestamp__mins'];
}
if (isset($_POST['dt_to_timestamp__sec'])) {
$dt_to_timestamp__sec = $_POST['dt_to_timestamp__sec'];
}


if (isset($_POST['dt_to_timestamp__date'])) {
if (isset($_POST['dt_to_timestamp__month'])) {
if (isset($_POST['dt_to_timestamp__year'])) {
if (isset($_POST['dt_to_timestamp__hours'])) {
if (isset($_POST['dt_to_timestamp__mins'])) {
if (isset($_POST['dt_to_timestamp__sec'])) {


echo date(mktime($dt_to_timestamp__hours, $dt_to_timestamp__mins, $dt_to_timestamp__sec, $dt_to_timestamp__month, $dt_to_timestamp__date, $dt_to_timestamp__year));
}
}
}
}
}
}
?>

What I am missing ?

 

-Thanks

 

timestamp.php

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.