PHP or Javascript indicating the date and time from the server and local time

Does anyone have a simple code to show week nr, date and time taken from a web server?

And then another code that gets time from the local computer?

I am looking for JS or PHP code

+4
source share
1 answer

On the server side you can use ( PHP )

 $currentWeekNumber = (int)date('w'); // ISO-8601 week number of the year $date = date('H:i:s dm-Y'); // for example (you can use different format) 

The JS implementation is not so trivial. There is no built-in function, but here is an example of what has been done.

 function getWeek (getdate) { var a, b, c, d, e, f, g, n, s, w; $y = getdate.getFullYear(); $m = getdate.getMonth() + 1; $d = getdate.getDate(); if ($m <= 2) { a = $y - 1; b = (a / 4 | 0) - (a / 100 | 0) + (a / 400 | 0); c = ((a - 1) / 4 | 0) - ((a - 1) / 100 | 0) + ((a - 1) / 400 | 0); s = b - c; e = 0; f = $d - 1 + (31 * ($m - 1)); } else { a = $y; b = (a / 4 | 0) - (a / 100 | 0) + (a / 400 | 0); c = ((a - 1) / 4 | 0) - ((a - 1) / 100 | 0) + ((a - 1) / 400 | 0); s = b - c; e = s + 1; f = $d + ((153 * ($m - 3) + 2) / 5) + 58 + s; } g = (a + b) % 7; d = (f + g - e) % 7; n = (f + 3 - d) | 0; if (n < 0) { w = 53 - ((g - s) / 5 | 0); } else if (n > 364 + s) { w = 1; } else { w = (n / 7 | 0) + 1; } $y = $m = $d = null; return w; } weeknumber = getWeek(new Date()); 

UPD: Today momentjs is capable of a lot of dates in JS.

+2
source

All Articles