我有一个php文件,我稍后将更改为HTML文件的形式,当前的约束是: - 使用Javascript的日期格式。
她的脚本如下面的片段:
<script type="text/javascript" src="js/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="js/script.js"></script>
<?php
/* Set start and end dates here */
$startDate = strtotime("15 August 2012 12:00:00");
$endDate = strtotime("15 November 2012 12:00:00");
/* /Set start and end dates here */
?>
<script type="text/javascript">
$(document).ready(function(){
JBCountDown({
secondsColor : "#ffdc50",
minutesColor : "#9cdb7d",
hoursColor : "#378cff",
daysColor : "#ff6565",
startDate : "<?php echo $startDate; ?>",
endDate : "<?php echo $endDate; ?>",
now : "<?php echo strtotime('now'); ?>",
seconds : "<?php echo date("s"); ?>"
});
});
</script>
请帮助我克服它。 我想在javascript中运行一个php脚本。
示例:
<script type="text/javascript">
$(document).ready(function(){
JBCountDown({
secondsColor : "#ffdc50",
minutesColor : "#9cdb7d",
hoursColor : "#378cff",
daysColor : "#ff6565",
startDate : startDate, //format time in JS
endDate : endDate, //format time in JS
now : strtotime('now'), //format time in JS
seconds : date("s")
});
});
</script>
请帮忙, 此致
答案 0 :(得分:2)
这一切都可以在javascript中完成。
<script type="text/javascript">
$(document).ready(function(){
//http://www.convert-unix-time.com/
var unix = Math.round(+new Date()/1000); //unix timestamp for todays date
//alert(unix);
JBCountDown({
secondsColor : "#ffdc50",
secondsGlow : "none",
minutesColor : "#9cdb7d",
minutesGlow : "none",
hoursColor : "#378cff",
hoursGlow : "none",
daysColor : "#ff6565",
daysGlow : "none",
startDate : "1362096000 ", //unix timestamp for ' Friday 1st March 2013 12:00:00 AM'
endDate : "1373328000", //unix timestamp for 'Tuesday 9th July 2013 01:00:00 AM'
now : unix,
seconds : unix % 60 //unix timestamp for seconds in realtime
});
});
</script>
答案 1 :(得分:0)
使用strtotime()和date():
$originalDate = "2010-03-21";
$newDate = date("d-m-Y", strtotime($originalDate));
答案 2 :(得分:0)
<?php
/* Set start and end dates here */
$startDate = new DateTime("15 August 2012 12:00:00");
$endDate = new DateTime("15 November 2012 12:00:00");
/* /Set start and end dates here */
print $startDate->format('FORMAT');
?>
查看所有日期时间格式:http://www.php.net/manual/en/datetime.formats.php