Editing
Sleep in Mandarin
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== 方法 1:sleep === 在 {{Linux}} 和 {{Mac}} 上測試<ref>[https://bash.cyberciti.biz/guide/Perform_arithmetic_operations 執行算術運算 - Linux Shell 腳本編寫教學 - 初學者手冊]</ref><ref>[https://linuxize.com/post/how-to-use-linux-sleep-command-to-pause-a-bash-script/ Linux Sleep 命令(暫停 Bash 腳本) | Linuxize]</ref> <pre> # 列印當前日期與時間 echo $(date '+%Y-%m-%d %H:%M:%S') # 暫停 5 到 65 秒 timeout=$(($RANDOM * 60 / 32768 + 5)) sleep $timeout # 列印當前日期與時間 echo $(date '+%Y-%m-%d %H:%M:%S') </pre> 暫停幾 [https://en.wikipedia.org/wiki/Microsecond 微秒]<ref>[https://serverfault.com/questions/151109/how-do-i-get-the-current-unix-time-in-milliseconds-in-bash 如何在 Bash 中獲取當前 Unix 時間(毫秒)? - Server Fault]</ref>。在 {{Linux}} 上測試 <pre> # 列印當前 Unix 時間戳,例如 1598346362244 date +%s%N # 暫停 1 毫秒 = 0.001 秒 sleep 0.001s # 列印當前 Unix 時間戳 date +%s%N </pre> 在 {{Mac}} 上測試暫停幾微秒 <pre> # 列印當前 Unix 時間戳,例如 1598346362244 php -r 'echo microtime(TRUE) . PHP_EOL;' # 暫停 1 毫秒 = 0.001 秒 sleep 0.001s # 列印當前 Unix 時間戳 php -r 'echo microtime(TRUE) . PHP_EOL;' </pre> 暫停幾毫秒(1 秒 = 1000 毫秒)例如 1671090194.136471987<ref>[https://apple.stackexchange.com/questions/135742/time-in-milliseconds-since-epoch-in-the-terminal macos - 自紀元以來的時間(毫秒) - 在終端 - Ask Different]</ref> <pre> # 列印當前 Unix 時間戳(毫秒),例如 1671090194.136471987 perl -MTime::HiRes=time -e 'printf "%.9f\n", time' # 暫停 1 毫秒 = 0.001 秒 sleep 0.001s # 列印當前 Unix 時間戳 perl -MTime::HiRes=time -e 'printf "%.9f\n", time' </pre>
Summary:
Please note that all contributions to LemonWiki共筆 are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see
LemonWiki:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Main page
Current events
Recent changes
Random page
Help
Categories
Tools
What links here
Related changes
Special pages
Page information