PHP Date
Fungsi date() digunakan untuk memformat waktu dan tanggal.
Sintaks
date(format,timestamp) |
Parameter | Keterangan |
format | Required. Specifies the format of the timestamp |
timestamp | Optional. Specifies a timestamp. Default is the current date and time (as a timestamp) |
Timestamp
Timestamp adalah jumlah detik sejak January 1, 1970 00:00:00 GMT. Juga dikenal sebagai Unix Timestamp.
Format Tanggal
- d – format hari (01-31)
- m – format bulan (01-12)
- Y – format tahun
Program14-1.php
<?php echo date("Y/m/d"); echo "<br />"; echo date("Y.m.d"); echo "<br />"; echo date("Y-m-d"); ?> |
output:
2006/07/11 2006.07.11 2006-07-11 |
Fungsi mktime() akan memberikan nilai Unix timestamp untuk tanggal tertentu.
Sintaks
mktime(hour,minute,second,month,day,year,is_dst) |
Program14-2.php
<?php $tomorrow = mktime(0,0,0,date("m"),date("d")+1,date("Y"));
echo "Tomorrow is ".date("Y/m/d/", $tomorrow); ?> |
output:
Tomorrow is 2006/07/12 |
0 komentar:
Posting Komentar