New answers tagged

1

I recommend you read this article from RedHat. Hardware Clock, is a clock that runs independently of any control program running in the CPU and even when the machine is powered off so it can keep track of the current time. And hwclock is a utility for accessing the Hardware Clock - also referred to as the Real Time Clock (RTC) or CMOS clock. You can ...


0

The hardware clock is the real-time clock (these days part of the southbridge chip) the same subsystem also stores BIOS settings, and the hardware clock can often be set via the BIOS settings menus. On linux the hwclock tool can be used to access the hardware clock from the command-line. Using UTC for the hardware clock give more consistent results on ...


2

I'm not sure if I understand you, but it looks like you want to convert time between timezones. Since, afaik, London uses GMT+0, I would do something like this: date --date="TZ=\"Europe/London\" $dateto" +%T This will take your local time from dateto and output the time in London, given that the time in dateto is your current local time. Should I be ...


4

With zsh: zmodload zsh/datetime strftime -s t -r %Y%m%d%H%M 201607131001 LC_ALL=C strftime '%I:%M %p %B %d, %Y' $t With busybox date: date -D %Y%m%d%H%M -d 201607131001 +'%I:%M %p %B %d, %Y' With AT&T ast-open date: date -p %Y%m%d%H%M -d 201607131001 +'%I:%M %p %B %d, %Y' With BSD date: date -jf %Y%m%d%H%M +'%I:%M %p %B %d, %Y' 201607131001 ...


9

Assuming you have GNU date, we need to add a space between the date and time and pass it with -d $ date -d "20160713 1001" Wed Jul 13 10:01:00 EDT 2016 We can do that split pretty easily with parameter expansions. e.g $ d=201607131001 $ date -d "${d%????} ${d#????????}" Wed Jul 13 10:01:00 EDT 2016 You can then use the standard + formatting strings to ...


0

\D{%r} displays 12 hour time in the HH:MM:SS AM/PM format.


0

Actually, it is simple only if you make a lot of assumptions. Since the question did not provide an example, here are some realistic assumptions: the delimiter between fields of the date is / csv files have more than one column the date can be in any column other columns might have numbers The example by Stephen did not address the last three of these. ...


1

Try: eval "`date +'@ s = (86400 - %S) - 60 * (%M + 60 * %H)'`"; echo $s However note that in timezones that have winter and summer time, it won't give the right result if called on the day of the switch from/to summer time, before the switch (which generally happen very early in the morning). Beware that in csh, arithmetic operators are right-...


0

this reads like a homework question. given that you are constrained to only getting hours minutes and seconds you will have to take those numbers and do arithmentic. the arithmetic is not complex, I'm sure you can work it out. this will not give a reliable result because there is a race condition if the minute changes during the determination of those ...


2

Using busybox date seems like the right choice: $ busybox date -uD '%d/%m/%Y' -d '09/07/2016' Sat Jul 9 00:00:00 UTC 2016 That works because busybox date accepts a format (-D) to read the date inside -d. To make the command more reliable and to build exactly the format you ask for: $ LC_ALL=C busybox date -uD '%d/%m/%Y' -d '09/07/2016' +'%a, %b %d, %Y %...


3

Assuming you have GNU date (or another date program that understands -d and works properly) and using bash: You can use the -d flag to report time at various points. So, for example % date -d "00:00:00 tomorrow" Sat Jul 16 00:00:00 EDT 2016 We can use this to report on seconds with +%s % date -d "00:00:00 tomorrow" +%s 1468641600 We know our current ...


0

tail -100 access.* | awk '{ print $1 }' | sort | uniq -c | sort -n or cat access.* | grep "28/Mar/2016" | awk '{ print $1 }' | sort | uniq -c | sort -n


4

Note that date -d is a GNU extension. The syntax it expects is fixed and independent from the locale. In particular, it does not use POSIX getdate() to parse the date (even though the interface GNU date uses used to be called getdate() as well). Some builds of some versions of busybox also recognise a -d option, but the range of supported formats is ...


1

From info date For numeric months, the ISO 8601 format YEAR-MONTH-DAY is allowed When months are written literally, the calendar date may be given as any of the following: DAY MONTH YEAR DAY MONTH MONTH DAY YEAR DAY-MONTH-YEAR So main rule All these strings specify the same calendar date: 1972-09-24 # ISO 8601. 72-9-24 # ...


-1

Use the format option: date -d `date -d '09/07/2016' +"%d/%m/%Y"` +"%a, %b %-d, %Y 12:00:00 AM"


4

This sed statement will add a 0 to the first two numbers if they are single digits: sed -e 's!^[0-9]/!0&!' -e 's!/\([0-9]/\)!/0\1!' e.g. $ cat x 1/1/1970 10/1/2000 10/10/2100 $ sed -e 's!^[0-9]/!0&!' -e 's!/\([0-9]/\)!/0\1!' x 01/01/1970 10/01/2000 10/10/2100


2

Your assumption that date does not require an internet connection is correct. It simply outputs the current time stored in the system-clock. (More information on time and date commands) The hardware clock is a battery-operated circuit on the motherboard that maintains the current time while the system is powered off or unplugged. On system startup, the ...


4

date makes no effort to synchronize with anything at all, and merely makes some system call (that on linux a strace date ... may or may not show) to lookup the time since the epoch as known by the system. The system itself may synchronize with the BIOS clock, or if a virtual machine may obtain the current time from the parent it runs under, or may use NTP (...


1

date --date - does not accept standard input; try date +"%s" --date "$(echo '"tester_row_____",0,"2016-07-04T01:42:28Z","2016-07-04T02:00:58Z"' | cut -c 22-41)" instead. This will run your string manipulation pipeline in a subshell, and use the output of that as a parameter for date.


3

according to man date %k hour, space padded ( 0..23); same as %_H - (hyphen) do not pad the field _ (underscore) pad with spaces 0 (zero) pad with zeros e.g. %-H will not pad date +=%-H- =9- If you want to go to 24 hour format, with a leading 0, use %H. If you prefer am/pm, you can use %I, you must include also %p to have am/pm ...


0

You can fake the time for most applications with the aptly named faketime. Run faketime 'yesterday' myapp to make myapp believe that it's yesterday. Faketime works by intercepting library calls made by the application. It only works with dynamically-linked applications, but that's usually good enough. Your server is probably taking the time from the ...


0

If you want files to have a modification date in the past, you can just use the touch command. Depending on what you want to demo, this might already be sufficient. Since your actual requirements are not really clear, it's hard to tell whether changing the system clock with all the associated hassle is a reasonable approach.



Top 50 recent answers are included