{"id":9343,"date":"2025-01-22T01:02:00","date_gmt":"2025-01-22T06:02:00","guid":{"rendered":"https:\/\/www.both.org\/?p=9343"},"modified":"2025-01-21T15:56:49","modified_gmt":"2025-01-21T20:56:49","slug":"how-linux-keeps-time","status":"publish","type":"post","link":"https:\/\/www.both.org\/?p=9343","title":{"rendered":"How Linux keeps time"},"content":{"rendered":"<div class=\"pld-like-dislike-wrap pld-template-1\">\r\n    <div class=\"pld-like-wrap  pld-common-wrap\">\r\n    <a href=\"javascript:void(0)\" class=\"pld-like-trigger pld-like-dislike-trigger  \" title=\"\" data-post-id=\"9343\" data-trigger-type=\"like\" data-restriction=\"cookie\" data-already-liked=\"0\">\r\n                        <i class=\"fas fa-thumbs-up\"><\/i>\r\n                <\/a>\r\n    <span class=\"pld-like-count-wrap pld-count-wrap\">    <\/span>\r\n<\/div><\/div>\n<p>Knowing the exact time is important to computers for many reasons. A GPS, which is a computer, needs to know the exact time so it can determine your exact location. Financial systems require the exact time so that transactions can be accurately timestamped and thus sorted into the correct time-sequence. Most of us just need to display an accurate time on our desktop or use the timestamps on our files so we can find the most recent versions.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The Epoch<\/h2>\n\n\n\n<p>The term &#8220;<a href=\"https:\/\/en.wikipedia.org\/wiki\/Epoch\" target=\"_blank\" rel=\"noreferrer noopener\">epoch<\/a>&#8221; refers to the reference point for timekeeping of any sort. In computing, <a href=\"https:\/\/en.wikipedia.org\/wiki\/Epoch_(computing)\" target=\"_blank\" rel=\"noreferrer noopener\">epoch<\/a> refers to a specific, fixed moment in time from which system time is measured. Time is measured in seconds, i.e., ticks, since the epoch. I usually refer to this as Unix or Linux time.<\/p>\n\n\n\n<p>Different computer systems use different dates, but the Epoch for Unix and Linux is defined as 1970-01-01 00:00:00 GMT. Time is measured in seconds since that Epoch. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Working with dates<\/h2>\n\n\n\n<p>Here are a few examples using the <strong>date<\/strong> command to illustrate the relationship between the Linux time and the date and time strings we humans can easily interpret. The Linux <strong>date<\/strong> command can tell us the current time in a format defined by the locale.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ <strong>date<\/strong>\nTue Jan 21 10:18:41 AM EST 2025<\/code><\/pre>\n\n\n\n<p>We can also use the <strong>date<\/strong> command to display the number of seconds since the Epoch. This is a universal number and independent of local time zone and locale formats.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ <strong>date +%s<\/strong>\n1737491563<\/code><\/pre>\n\n\n\n<p>Then we can use it to convert the number of seconds displayed in the previous command back into a human-readable date. This converts the seconds into a date and time string based on the locale and time zone specified in the operating system&#8217;s configuration.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ <strong>date --date='@1737491563'<\/strong>\nTue Jan 21 03:32:43 PM EST 2025<\/code><\/pre>\n\n\n\n<p>It can also give us the number of seconds since the Epoch for a specified date and time.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ date --date='2025-01-25 15:02:21 0500' +%s\n1737817341<\/code><\/pre>\n\n\n\n<p>The date command has many interesting options you can use for display and manipulation of dates. The man page for the date command has enough information for most users, but the info page (<strong> info date<\/strong>) contains much more information and many examples illustrating the use of the date command. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Knowing the exact time is important to computers for many reasons. A GPS, which is a computer, needs<\/p>\n","protected":false},"author":2,"featured_media":3688,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_lmt_disableupdate":"","_lmt_disable":"","footnotes":""},"categories":[5],"tags":[689,691,690],"class_list":["post-9343","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux","tag-date","tag-date-command","tag-time"],"modified_by":"David Both","_links":{"self":[{"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/9343","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=9343"}],"version-history":[{"count":8,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/9343\/revisions"}],"predecessor-version":[{"id":9352,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/9343\/revisions\/9352"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/media\/3688"}],"wp:attachment":[{"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=9343"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=9343"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=9343"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}