Difference between revisions of "Show current time"

From LemonWiki共筆
Jump to: navigation, search
(Created page with "* {{kbd | key= date}} ({{Linux}}) output the system date: Thu Oct 25 15:05:10 CST 2012 <ref>[http://linux.vbird.org/linux_server/0440ntp.php 鳥哥的 Linux 私房菜 -- NTP...")
 
m (Windows DOS)
(7 intermediate revisions by the same user not shown)
Line 1: Line 1:
* {{kbd | key= date}} ({{Linux}}) output the system date: Thu Oct 25 15:05:10 CST 2012 <ref>[http://linux.vbird.org/linux_server/0440ntp.php 鳥哥的 Linux 私房菜 -- NTP 時間伺服器]</ref><ref>[https://en.wikipedia.org/wiki/DATE_(command) DATE (command) - Wikipedia, the free encyclopedia]</ref>
+
Multiple approached to show current time
 +
 
 +
== Linux BASH ==
 +
* {{kbd | key= date}} ({{Linux}}) output the system date: 'Thu Oct 25 15:05:10 CST 2012' <ref>[http://linux.vbird.org/linux_server/0440ntp.php 鳥哥的 Linux 私房菜 -- NTP 時間伺服器]</ref><ref>[https://en.wikipedia.org/wiki/DATE_(command) DATE (command) - Wikipedia, the free encyclopedia]</ref>
 +
** {{kbd | key= <nowiki>echo $(date '+%Y-%m-%d %H:%M:%S')</nowiki>}} ({{Linux}}& {{Mac}}) example output: '{{Template:Today}} {{CURRENTTIME}}:06' {{exclaim}} server timezone dependent
 
* {{kbd | key= TZ=Asia/Taipei date}} ({{Linux}}) output the time from the Taipei/CST timezone <ref>[http://unix.stackexchange.com/questions/48101/how-can-i-have-date-output-the-time-from-a-different-timezone How can I have `date` output the time from a different timezone? - Unix & Linux Stack Exchange]</ref>
 
* {{kbd | key= TZ=Asia/Taipei date}} ({{Linux}}) output the time from the Taipei/CST timezone <ref>[http://unix.stackexchange.com/questions/48101/how-can-i-have-date-output-the-time-from-a-different-timezone How can I have `date` output the time from a different timezone? - Unix & Linux Stack Exchange]</ref>
 +
 +
== Windows DOS ==
 
* {{kbd | key= date/t}} ({{Win}}) (parameter: /t will not ask you to change the current date)
 
* {{kbd | key= date/t}} ({{Win}}) (parameter: /t will not ask you to change the current date)
 
<pre>output:
 
<pre>output:
Line 12: Line 18:
 
OS in Mandarin Chinese (Windows 10): 2017/02/03 週五 15:35:31.61
 
OS in Mandarin Chinese (Windows 10): 2017/02/03 週五 15:35:31.61
 
</pre>
 
</pre>
* related pages: [[Time server]], [[PHP_and_MySQL_syntax#timestamp | timestamp in PHP and MySQL syntax]]
+
 
 +
If PHP was installed. (1) Saved the PHP execution result to the file `today.txt` (2) Read the file content and save to the variable '%TODAY%'
 +
<pre>command:
 +
php -r "echo date('Y-m-d);" > today.txt
 +
SET /P TODAY =< today.txt
 +
ECHO %TODAY%
 +
</pre>
 +
 
 +
output: `{{Template:Today}}`
 +
 
 +
== PHP & MySQL ==
 +
[[PHP and MySQL syntax]]
 +
 
 +
 
 +
[[PHP_and_MySQL_syntax#timestamp | timestamp in PHP and MySQL syntax]]
 +
 
 +
== Related pages ==
 +
[[Time server]]
 +
 
 +
== References ==
 +
<references />
  
 
[[Category:Programming]] [[Category:Linux]] [[Category:Windows]]
 
[[Category:Programming]] [[Category:Linux]] [[Category:Windows]]

Revision as of 10:39, 3 December 2019

Multiple approached to show current time

Linux BASH

  • date (Linux Os linux.png ) output the system date: 'Thu Oct 25 15:05:10 CST 2012' [1][2]
    • echo $(date '+%Y-%m-%d %H:%M:%S') (Linux Os linux.png & Mac Os mac.png ) example output: '2019-12-09 03:22:06' Icon exclaim.gif server timezone dependent
  • TZ=Asia/Taipei date (Linux Os linux.png ) output the time from the Taipei/CST timezone [3]

Windows DOS

  • date/t (Win Os windows.png ) (parameter: /t will not ask you to change the current date)
output:
OS in English: Thu 05/03/2012
OS in Mandarin Chinese (XP): 2012/05/03 星期四
OS in Mandarin Chinese (Windows 8, Windows Server 2008 R2): 2014/07/01 週二
OS in Mandarin Chinese (Windows 10): 週一 2019/12/02
  • prompt $d $t $_$P$G (Win Os windows.png [4])
output:
OS in Mandarin Chinese (Windows 10): 2017/02/03 週五 15:35:31.61

If PHP was installed. (1) Saved the PHP execution result to the file `today.txt` (2) Read the file content and save to the variable '%TODAY%'

command:
php -r "echo date('Y-m-d);" > today.txt
SET /P TODAY =< today.txt
ECHO %TODAY%

output: `2019-12-09`

PHP & MySQL

PHP and MySQL syntax


timestamp in PHP and MySQL syntax

Related pages

Time server

References