snipt

Ctrl+h for KB shortcuts

JavaScript

show content based on date

1
2
3
4
5
6
<script type="text/javascript">
	var myDate=new Date();
	myDate.setFullYear(2009,5,7);
	var today = new Date();
	if (today>myDate){document.getElementById('hidden').style.display = 'none';}
</script>
https://snipt.net/embed/782b5aa9783653194215d470f5078eee/
/raw/782b5aa9783653194215d470f5078eee/
782b5aa9783653194215d470f5078eee
js
JavaScript
6
2019-07-19T03:48:58
True
False
False
/api/public/snipt/6296/
show-content-based-on-date
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="o">&lt;</span><span class="nx">script</span> <span class="nx">type</span><span class="o">=</span><span class="s2">&quot;text/javascript&quot;</span><span class="o">&gt;</span> </span><span id="L-2"><a name="L-2"></a> <span class="kd">var</span> <span class="nx">myDate</span><span class="o">=</span><span class="k">new</span> <span class="nb">Date</span><span class="p">();</span> </span><span id="L-3"><a name="L-3"></a> <span class="nx">myDate</span><span class="p">.</span><span class="nx">setFullYear</span><span class="p">(</span><span class="mi">2009</span><span class="p">,</span><span class="mi">5</span><span class="p">,</span><span class="mi">7</span><span class="p">);</span> </span><span id="L-4"><a name="L-4"></a> <span class="kd">var</span> <span class="nx">today</span> <span class="o">=</span> <span class="k">new</span> <span class="nb">Date</span><span class="p">();</span> </span><span id="L-5"><a name="L-5"></a> <span class="k">if</span> <span class="p">(</span><span class="nx">today</span><span class="o">&gt;</span><span class="nx">myDate</span><span class="p">){</span><span class="nb">document</span><span class="p">.</span><span class="nx">getElementById</span><span class="p">(</span><span class="s1">&#39;hidden&#39;</span><span class="p">).</span><span class="nx">style</span><span class="p">.</span><span class="nx">display</span> <span class="o">=</span> <span class="s1">&#39;none&#39;</span><span class="p">;}</span> </span><span id="L-6"><a name="L-6"></a><span class="o">&lt;</span><span class="err">/script&gt;</span> </span></pre></div> </td></tr></table>
date, display, javascript

Bash

Time Synchronization using NTP

1
2
3
ntpdate 0.pool.ntp.org
ntpdate 1.pool.ntp.org
ntpdate 2.pool.ntp.org
https://snipt.net/embed/7a5f06bbebfe66af99f83573f419bbb9/
/raw/7a5f06bbebfe66af99f83573f419bbb9/
7a5f06bbebfe66af99f83573f419bbb9
bash
Bash
3
2019-07-21T05:14:48
True
False
False
/api/public/snipt/5641/
set-time-zone-1
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>ntpdate 0.pool.ntp.org </span><span id="L-2"><a name="L-2"></a>ntpdate 1.pool.ntp.org </span><span id="L-3"><a name="L-3"></a>ntpdate 2.pool.ntp.org </span></pre></div> </td></tr></table>
date, ntp, server, sync, system, time, zone

Bash

Set Time Zone

ln -sf /usr/share/zoneinfo/Asia/Calcutta /etc/localtime
https://snipt.net/embed/d829f54fa305c545d1a8db517e785ec4/
/raw/d829f54fa305c545d1a8db517e785ec4/
d829f54fa305c545d1a8db517e785ec4
bash
Bash
1
2019-07-21T05:14:51
True
False
False
/api/public/snipt/5640/
set-time-zone
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>ln -sf /usr/share/zoneinfo/Asia/Calcutta /etc/localtime </span></pre></div> </td></tr></table>
date, server, system, time, zone

PHP

How to format dates in drupal

1
2
3
4
5
<?php

print format_date(strtotime($node->field_event_date[0]['value']), 'custom', 'D, j M, Y \a\\t G:i' );

?>
https://snipt.net/embed/e20583cc48a355ace529b8cc52920655/
/raw/e20583cc48a355ace529b8cc52920655/
e20583cc48a355ace529b8cc52920655
php
PHP
5
2019-07-20T11:53:59
True
False
False
/api/public/snipt/4997/
how-to-format-dates-in-drupal
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?php</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a><span class="k">print</span> <span class="nx">format_date</span><span class="p">(</span><span class="nb">strtotime</span><span class="p">(</span><span class="nv">$node</span><span class="o">-&gt;</span><span class="na">field_event_date</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="s1">&#39;value&#39;</span><span class="p">]),</span> <span class="s1">&#39;custom&#39;</span><span class="p">,</span> <span class="s1">&#39;D, j M, Y \a\\t G:i&#39;</span> <span class="p">);</span> </span><span id="L-4"><a name="L-4"></a> </span><span id="L-5"><a name="L-5"></a><span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
date, drupal, format

Bash

Show an autoupdating clock in the console

1
2
3
4
5
6
7
8
#!/bin/bash

while true
do
  clear
  banner "Exact time" " `date | awk '{ print $4 }'`" "`date | awk '{ print $3$2" "$6 }'`"
  sleep 1
done
https://snipt.net/embed/b7b7737db23277e40d668c6f75a93df2/
/raw/b7b7737db23277e40d668c6f75a93df2/
b7b7737db23277e40d668c6f75a93df2
bash
Bash
8
2019-07-06T05:10:14
True
False
False
/api/public/snipt/4956/
show-an-autoupdating-clock-in-the-console
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a> <a href="#L-7">7</a> <a href="#L-8">8</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="ch">#!/bin/bash</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a><span class="k">while</span> <span class="nb">true</span> </span><span id="L-4"><a name="L-4"></a><span class="k">do</span> </span><span id="L-5"><a name="L-5"></a> clear </span><span id="L-6"><a name="L-6"></a> banner <span class="s2">&quot;Exact time&quot;</span> <span class="s2">&quot; `date | awk &#39;{ print </span><span class="nv">$4</span><span class="s2"> }&#39;`&quot;</span> <span class="s2">&quot;`date | awk &#39;{ print </span><span class="nv">$3$2</span><span class="s2">&quot;</span> <span class="s2">&quot;</span><span class="nv">$6</span><span class="s2"> }&#39;`&quot;</span> </span><span id="L-7"><a name="L-7"></a> sleep 1 </span><span id="L-8"><a name="L-8"></a><span class="k">done</span> </span></pre></div> </td></tr></table>
awk, banner, bash, clock, date

Python 3

date from iso date string

1
2
3
4
5
6
from datetime import date
from time import strptime

...
date(*strptime('2009-03-28', '%Y-%m-%d')[:3])
...
https://snipt.net/embed/01b319b2eb3f0af63746a93bd69b44d9/
/raw/01b319b2eb3f0af63746a93bd69b44d9/
01b319b2eb3f0af63746a93bd69b44d9
python3
Python 3
6
2019-07-16T10:31:03
True
False
False
/api/public/snipt/4549/
date-from-iso-date-string
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="kn">from</span> <span class="nn">datetime</span> <span class="k">import</span> <span class="n">date</span> </span><span id="L-2"><a name="L-2"></a><span class="kn">from</span> <span class="nn">time</span> <span class="k">import</span> <span class="n">strptime</span> </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a><span class="o">...</span> </span><span id="L-5"><a name="L-5"></a><span class="n">date</span><span class="p">(</span><span class="o">*</span><span class="n">strptime</span><span class="p">(</span><span class="s1">&#39;2009-03-28&#39;</span><span class="p">,</span> <span class="s1">&#39;%Y-%m-</span><span class="si">%d</span><span class="s1">&#39;</span><span class="p">)[:</span><span class="mi">3</span><span class="p">])</span> </span><span id="L-6"><a name="L-6"></a><span class="o">...</span> </span></pre></div> </td></tr></table>
date, python

PHP

Date au format UTC (RFC 822)

1
2
3
4
<?
date_default_timezone_set('UTC');
date(DATE_RFC822);
?>
https://snipt.net/embed/6407b574c86612ddcf19e23eb35539fb/
/raw/6407b574c86612ddcf19e23eb35539fb/
6407b574c86612ddcf19e23eb35539fb
php
PHP
4
2019-07-21T04:32:41
True
False
False
/api/public/snipt/4267/
date-au-format-utc-rfc-822
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?</span> </span><span id="L-2"><a name="L-2"></a><span class="nb">date_default_timezone_set</span><span class="p">(</span><span class="s1">&#39;UTC&#39;</span><span class="p">);</span> </span><span id="L-3"><a name="L-3"></a><span class="nb">date</span><span class="p">(</span><span class="nx">DATE_RFC822</span><span class="p">);</span> </span><span id="L-4"><a name="L-4"></a><span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
date, php, rfc822, utc

PHP

Current Year in PHP

<?php echo date('Y'); ?>
https://snipt.net/embed/3f00d70e1b2346943cbc44c8184073c5/
/raw/3f00d70e1b2346943cbc44c8184073c5/
3f00d70e1b2346943cbc44c8184073c5
php
PHP
1
2019-07-20T06:29:12
True
False
False
/api/public/snipt/3898/
current-year-in-php
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?php</span> <span class="k">echo</span> <span class="nb">date</span><span class="p">(</span><span class="s1">&#39;Y&#39;</span><span class="p">);</span> <span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
date, php