Skip to content

Instantly share code, notes, and snippets.

@gomasaba
Created November 2, 2011 05:09
Show Gist options
  • Save gomasaba/1332913 to your computer and use it in GitHub Desktop.
Save gomasaba/1332913 to your computer and use it in GitHub Desktop.
WEBでタイムスタンプとか・・・確認したいとか・・・
<html>
<head>
<style type="text/css">
/* Set up custom font and form width */
body {
margin-left: 10px;
font-family: Arial,sans-serif;
font-size: small;
}
.quickform {
min-width: 500px;
max-width: 600px;
width: 560px;
}
</style>
<title>Time to Unix</title>
</head>
<body>
<h3>Now:<?php echo time();?> <?php echo date('Y-m-d H:i:s');?></h3>
<?php
require_once 'HTML/QuickForm2.php';
require_once 'HTML/QuickForm2/Renderer.php';
$form = new HTML_QuickForm2('elements');
$form->addElement(
'text', 'unix', array('style' => 'width: 300px;'), array('label' => 'timstamp:')
);
$form->addElement(
'date', 'times', null,
array('format' => 'Y-m-d H:i:s', 'minYear' => date('Y')+10, 'maxYear' => 2001,'addEmptyOption'=>true)
);
$form->addElement(
'submit', 'submit', array('value' => 'submit')
);
$renderer = HTML_QuickForm2_Renderer::factory('default');
$form->render($renderer);
// Output javascript libraries, needed by hierselect
echo $renderer->getJavascriptBuilder()->getLibraries(true, true);
echo $renderer;
// outputting form values
if ('POST' == $_SERVER['REQUEST_METHOD']) {
$val = $form->getValue();
if(!empty($val['times'])){
$Y = ($val['times']['Y']) ? $val['times']['Y'] : date('Y');
$m = ($val['times']['m']) ? $val['times']['m'] : date('m');
$d = ($val['times']['d']) ? $val['times']['d'] : date('d');
$H = ($val['times']['H']) ? $val['times']['H'] : 0;
$i = ($val['times']['i']) ? $val['times']['i'] : 0;
$s = ($val['times']['s']) ? $val['times']['s'] : 0;
$unix = mktime($H, $i, $s, $m, $d, $Y);
}
if(!empty($val['unix'])){
$date = date('Y-m-d H:i:s',$val['unix']);
}else{
$date = date('Y-m-d H:i:s',$unix);
}
}
?>
<div style="padding:10px;border: 1px solid #ff0000;margin:10px;">
<dl>
<dt>Unix</dt>
<dd><?php echo $unix;?></dd>
<dt>Format</dt>
<dd><?php echo $date;?></dd>
</dl>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment