Kompai Paskaitos

date – getting time to your needs

hello, how to get time to see what time is now in linux command prompt? simply:
$ date
Mon May 10 15:56:05 EEST 2010
But i need with no spaces and colons… i use all mighty sed 🙂

$ date | sed 's/\ /_/g' | sed 's/:/-/g'
Hurray!?! No! I still need something else: YYYY-MM-DD HH:mm:ss howto get it? simply:
$ date +%Y-%m-%d\ %H:%M:%S
2010-05-10 15:57:01
How to set the date? simply:
$ date +%Y-%m-%d.%H:%M:%S -s "2010-05-03.12:56:01"
$ date
Mon May 3 12:56:05 EEST 2010

for setting up time you can simply get ntp (network time protocol) to sync your clock with pool severs 😉

By Ruslanas Gžibovskis

One reply on “date – getting time to your needs”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.