96网(LieHuo03.Net)教23程 在网页开发中,我们提交表单的时间往往转换为10位数的时间戳格式,在调用时却难住了一些同学,那么如何调用转换出来呢?
答:例如你调用的变量是$liehuo_times,那么在php中输出的语句就是:<?php echo date("Y-m-d H:i:s",$liehuo_times); ?>,怎么样,简单吧?
mysql里面存的时间是时间戳,10位数的
怎么才能用函数转换成正常的时间函数输出?
time();
是获得当前时间,但获得的是一整型
可以对此进行格式化
date("Y-m-d H:i:s", time()) ;
这样连时,分秒一起显示
date("Y-m-d ", time()); 只年示年月日
<?
echo "本机所在的时区:".date("T")."<BR>";
echo "PHP时间戳(UNIX秒):".mktime()."<BR>";
echo "PHP时间(本地格式化后):".date("Y-m-d H:i:s")."<HR>";
?>
<script language="">
<!–
var d;
function myDate(timestamp) {
d = new Date(timestamp);
var jstimestamp = (d.getFullYear())+"-"+(d.getMonth()+1)+"-"+(d.getDate())+" "+(d.getHours())+":"+(d.getMinutes())+":"+(d.getSeconds());
return jstimestamp;
}
var phptimestamp = <?=mktime()?>;
var jstimestamp = myDate((phptimestamp*1000));
document.writeln("PHP传递给时间:" + phptimestamp + "<BR>");
alert("PHP传递给时间:" + phptimestamp);
document.writeln("将PHP传递来的时间乘以1000后的时间戳:" + phptimestamp*1000 + "<BR>");
alert("将PHP传递来的时间乘以1000后的时间戳:" + phptimestamp*1000);
document.writeln("自身格式化PHP传递来乘以1000后的时间戳:" + d + "<BR>");
alert("自身格式化PHP传递来乘以1000后的时间戳:" + d);
document.writeln("转换后的时间:" + jstimestamp + "<BR>");
alert("转换后的时间:" + jstimestamp);
//–>
</script>
HP时间大的来分有两种,一是时间戳类型(1228348800),二是正常日期格式(2008-12-4)
所以存到数据库也有两种形式了(真正不止,我的应用就两种),时间戳类型我是保存为字符串的,这个是比较方便的.
正常日期类型是保存为DATE型的.
这两个要注意一下,我平时用两种,所以,前几天建的表,把时间类型存为DATE的,我还一直用时间戳保存,一直资料写不进表,调试了好久的才知错误之处,是类型不符合,不给写入库.
像上面的时间戳是比较方便,但,显示的时候,不至于把这个1228348800串给客户看吧,GOD NOWS!
所以就用到了这两个的转换,先说一下如何取得当前的时间戳,$date1=time();这样就取得当前的时间戳了,要转回2008-12-4这种格式呢, 用到date()这个函数了,在PHP中date()函数比较常用,如取得当前日期,可以用$date2=date(‘Y-m-d’);,关于里面参数的意思,如不懂就查一下php的手册了.
好,言归正传,把1228348800转成2008-12-4格式代码如下:
$date3=date(‘Y-m-d H:i:s’,"1228348800");
这样就OK了,如还想得到小时,分钟秒,只要把’Y-m-d’改一下就可以了,不过要注意一下,PHP时间还像有8个小时的误差.加上就OK了.
时间戳转正常日期有了,反之呢,把正常日期格式转为时间戳呢,请看如下代码:
$year=((int)substr("2008-12-04",0,4));//取得年份
$month=((int)substr("2008-12-04",5,2));//取得月份
$day=((int)substr("2008-12-04",8,2));//取得几号
echo mktime(0,0,0,$month,$day,$year);
这样就能把正常日期转成时间戳了,这里如果有时分秒也是同理,
注意:php5.1以上时间戳会与实际时间相差8小时,解决办法如下
1、最简单的方法就是不要用php5.1以上的版本–显然这是不可取的方法!!!
2、修改php.ini。打开php.ini查找date.timezone 去掉前面的分号= 后面加Asia/Shanghai,重启apache服务器即可–缺点就是如果程序
放到别人的服务器上,不能修改php.ini,那就奈何不得了。
3、在程序中添加时间的初始化的语句的 即:“date_default_timezone_set("Asia/Shanghai"); ”这个可以由程序员任意设置,我的推
荐。
时区标识符,大陆内地可用的值是:PRC,Asia/Chongqing ,Asia/Shanghai ,Asia/Urumqi (依次为中国,重庆,上海,乌鲁木齐) ,Etc/GMT-8,Asia/Harbin
港台地区可用:Asia/Macao ,Asia/Hong_Kong ,Asia/Taipei (依次为澳门,香港,台北)
还有新加坡:Asia/Singapore
波比源码 » php时间戳和正常时间显示的转换代码
order levaquin 250mg pill levofloxacin tablet
sildenafil buy online sildenafil 100mg canada purchase estrace generic
prednisone 5mg sale deltasone 40mg usa sildenafil women
order alendronate 35mg generic ibuprofen 600mg pepcid uk
molnunat sale naproxen 250mg tablet prevacid for sale
order provera 5mg sale order provera 5mg for sale cyproheptadine 4 mg sale
generic modafinil 100mg legit canadian pharmacy online ivermectin
norvasc 10mg cheap oral tadalafil 20mg tadalafil 5mg
prilosec 10mg uk order research paper real money casino online usa
buy an essay cheap buy viagra 100mg generic viagra 100mg cost
flagyl 400mg usa augmentin 1000mg price order bactrim 960mg generic
order sildenafil generic viagra 50mg us cialis next day delivery
purchase azithromycin online cheap order azithromycin 500mg pills buy gabapentin 100mg
buy deltasone generic mebendazole usa vermox online buy
tadacip sale purchase indocin pills buy indocin pills
buy terbinafine for sale order amoxicillin 250mg pill trimox online
buy tadalafil 10mg pill cialis 20 mg price buy generic tadalafil 10mg
online poker free online casino slots no download casino online blackjack
ivermectin 4000 buy avlosulfon generic buy avlosulfon 100mg for sale
casino card games playing poker online play great poker online
altace 5mg price purchase glimepiride pills buy etoricoxib 60mg online cheap
doxycycline 200mg oral buy ventolin 4mg generic clindamycin generic
buy olmesartan 10mg buy verapamil 240mg generic order depakote 250mg pill
oral diamox 250 mg buy isosorbide 40mg sale generic imuran
lanoxin usa purchase lanoxin online cheap buy molnunat 200 mg online
buy coreg generic ditropan 5mg ca elavil without prescription
nortriptyline 25mg generic buy generic nortriptyline order paroxetine 10mg sale
order famotidine generic oral famotidine 20mg remeron 30mg without prescription
doxycycline 200mg oral chloroquine cost methylprednisolone 4mg tablet
buy requip 2mg generic buy rocaltrol 0.25mg generic labetalol canada
provigil medication order modafinil 200mg generic phenergan cost
order accutane generic prednisone 5mg cost ampicillin 250mg for sale
home remedies for ed erectile dysfunction generic propecia buy generic proscar 1mg
ondansetron 4mg over the counter buy amoxil 1000mg online cheap buy bactrim 960mg pill
ventolin inhalator order online order ventolin 2mg for sale purchase augmentin sale
buy generic modafinil 100mg order lopressor without prescription generic metoprolol 50mg
order azathioprine 25mg pills buy imuran 25mg online cheap purchase naproxen generic
ditropan for sale cost trileptal 300mg trileptal 300mg oral
omnicef 300 mg over the counter order omnicef 300mg pantoprazole us
buy zocor 10mg pills order zocor 10mg without prescription sildenafil overnight delivery
buy avlosulfon 100 mg sale mesalamine for sale tenormin 50mg cheap
purchase promethazine pills order promethazine 25mg generic cialis tadalafil 40mg
buy zetia no prescription tetracycline 500mg canada order methotrexate 10mg generic
levofloxacin pills levaquin online order zyban 150mg drug
cetirizine pills sertraline 50mg for sale zoloft online order
femara price purchasing viagra on the internet purchase sildenafil sale
buy tadalafil generic buy ed pills cheap causes of ed
buy amoxil without prescription buy amoxicillin 250mg online cheap buy prednisolone no prescription
isotretinoin 10mg without prescription accutane without prescription buy azithromycin 250mg generic
albuterol 4mg oral buy albuterol without prescription levothyroxine buy online
buy prednisolone online buy generic gabapentin lasix 40mg generic
clomid canada clomid 100mg usa hydroxychloroquine for sale
order vibra-tabs generic buy albuterol 4mg pills cheap augmentin 625mg
cheap atenolol 50mg cheap femara 2.5 mg order femara generic
albendazole over the counter order albenza 400mg generic provera 10mg canada
crestor 10mg pills zetia order motilium order
brand sumatriptan 50mg cost levofloxacin cost avodart 0.5mg
sumycin online order order lioresal online buy lioresal online cheap
buy generic toradol online toradol us inderal 10mg price
brand duloxetine 40mg cymbalta drug piracetam pills
buy betnovate generic oral betnovate 20 gm sporanox 100mg oral
order combivent 100 mcg pill buy ipratropium pills for sale zyvox 600mg pills
buy nebivolol no prescription valsartan 80mg for sale clozapine 100mg oral
cost simvastatin 10mg purchase valtrex generic order sildenafil 100mg online cheap
tadalafil 5mg over the counter buy tadalafil 40mg generic sildenafil 100mg over the counter
order cefadroxil 500mg generic where can i buy propecia proscar pills
fluconazole oral buy fluconazole sale oral ciprofloxacin 1000mg
buy generic estrace buy estradiol generic prazosin generic
buy vermox pills for sale retin gel oral tadalis pills
buy cleocin pills for sale clindamycin for sale buy sildenafil 100mg generic
avanafil pills order tadalafil 10mg online voltaren 100mg drug
order indocin 50mg generic buy terbinafine online cheap buy suprax 200mg
nolvadex 20mg cheap order ceftin online cheap buy ceftin 500mg online cheap
minocycline without prescription minocycline 100mg brand buy actos 30mg for sale
purchase leflunomide purchase sulfasalazine online cheap sulfasalazine 500mg without prescription
brand azipro buy prednisolone 5mg buy neurontin generic
order cialis 20mg order generic viagra 50mg cialis order
buy furosemide 100mg sale doxycycline 100mg canada generic allergy pills
order generic vardenafil 10mg order vardenafil 20mg online cheap plaquenil 400mg over the counter
buy ramipril 10mg online buy altace cost etoricoxib 60mg
order mesalamine 800mg generic buy azelastine 10ml sprayers purchase irbesartan pills
olmesartan 20mg uk order olmesartan sale cost divalproex
purchase adalat pill buy nifedipine generic buy fexofenadine 120mg for sale
buy amlodipine 5mg oral prinivil omeprazole medication
lopressor oral oral lopressor 100mg buy medrol generic
order aristocort pills claritin 10mg drug order loratadine for sale
buy ampicillin 250mg online cheap order ciprofloxacin 1000mg pills buy flagyl pills
buy erythromycin 500mg generic order fildena 50mg generic buy tamoxifen sale
buy topiramate without prescription buy generic levaquin 250mg buy levaquin medication
buy robaxin 500mg sale cost sildenafil 50mg order generic suhagra 100mg
avodart over the counter purchase mobic pill order meloxicam online
buy generic aurogra for sale sildenafil for men over 50 buy generic estradiol for sale
celebrex 200mg brand buy zofran 8mg sale order zofran 8mg online cheap
cialis 10mg pills buy generic viagra 100mg viagra 25mg
tadacip pill tadacip buy online order indocin 50mg capsule
order tadalafil 5mg for sale buy generic diflucan over the counter new ed drugs
buy sulfasalazine 500mg pill verapamil 120mg ca calan 120mg canada
meclizine 25mg uk order generic spiriva buy minocycline tablets
order azathioprine 50mg sale purchase lanoxin pill telmisartan 20mg for sale
buy ed pills fda sildenafil 100mg generic sildenafil generic
free samples of ed pills buy tadalafil 40mg pill cost cialis 40mg
buy ed pills cheap tadalafil 5mg generic order tadalafil 10mg generic
dapsone 100mg sale perindopril 4mg tablet perindopril 8mg generic
fexofenadine order online glimepiride 4mg over the counter glimepiride online
order terazosin 1mg pill arava 20mg sale tadalafil 20mg over the counter
arcoxia medication order arcoxia 60mg generic order azelastine generic
avapro for sale buy irbesartan for sale buy buspar tablets
where to buy amiodarone without a prescription order amiodarone 100mg generic where to buy dilantin without a prescription
brand biltricide buy hydrochlorothiazide 25 mg pill periactin ca
nitrofurantoin drug generic nitrofurantoin 100 mg order nortriptyline generic
buy fluvoxamine tablets cymbalta sale buy cheap generic cymbalta
glucotrol 5mg ca glucotrol medication betnovate 20gm canada
oral anacin buy acetaminophen 500 mg for sale cost pepcid
brand clomipramine 50mg itraconazole 100 mg drug progesterone ca
diovan tablet clozaril cost buy combivent 100 mcg sale
cheap decadron 0,5 mg buy starlix 120mg online order starlix pills
order trileptal 300mg for sale urso 300mg tablet actigall brand
order bupropion online cheap zyrtec 10mg usa atomoxetine pills
buy ciprofloxacin medication order generic lincomycin buy generic duricef over the counter
buy quetiapine 50mg online order lexapro 20mg online cheap order generic lexapro
order lamivudine order epivir sale quinapril 10 mg ca
fluoxetine canada femara 2.5 mg us purchase letrozole online
buy zebeta pills pill ethambutol oxytetracycline pills