snipt

Ctrl+h for KB shortcuts

TypeScript

String to Date conversion

1
2
3
4
convertStrToDateObj(dateStr): any {
	const dateStrArr = dateStr.split('-');
	return new Date(parseInt(dateStrArr[0], 10), parseInt(dateStrArr[1], 10) - 1, parseInt(dateStrArr[2], 10));
}
https://snipt.net/embed/8a42112e50cd659303ba9b47faecf35a/
/raw/8a42112e50cd659303ba9b47faecf35a/
8a42112e50cd659303ba9b47faecf35a
ts
TypeScript
4
2019-07-02T00:36:40
True
False
True
Jul 02, 2019 at 12:27 AM
/api/public/snipt/148547/
1d8f2363
<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="nx">convertStrToDateObj</span><span class="p">(</span><span class="nx">dateStr</span><span class="p">)</span><span class="o">:</span> <span class="nx">any</span> <span class="p">{</span> </span><span id="L-2"><a name="L-2"></a> <span class="kr">const</span> <span class="nx">dateStrArr</span> <span class="o">=</span> <span class="nx">dateStr</span><span class="p">.</span><span class="nx">split</span><span class="p">(</span><span class="s1">&#39;-&#39;</span><span class="p">);</span> </span><span id="L-3"><a name="L-3"></a> <span class="k">return</span> <span class="k">new</span> <span class="nb">Date</span><span class="p">(</span><span class="nb">parseInt</span><span class="p">(</span><span class="nx">dateStrArr</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="mi">10</span><span class="p">),</span> <span class="nb">parseInt</span><span class="p">(</span><span class="nx">dateStrArr</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="mi">10</span><span class="p">)</span> <span class="o">-</span> <span class="mi">1</span><span class="p">,</span> <span class="nb">parseInt</span><span class="p">(</span><span class="nx">dateStrArr</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span> <span class="mi">10</span><span class="p">));</span> </span><span id="L-4"><a name="L-4"></a><span class="p">}</span> </span></pre></div> </td></tr></table>
Conversion, Date, Typescript

Text only

HTTP-Date (HTTP/1.1 RFC-2616) regular expression validation (RFC-1123/RFC-850/ANSI C asctime)

(?:(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun), (?:[0-2][0-9]|3[01]) (?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \d{4} (?:[01][0-9]|2[0-3]):[012345][0-9]:[012345][0-9] GMT|(?:Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday), (?:[0-2][0-9]|3[01])-(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)-\d{2} (?:[01][0-9]|2[0-3]):[012345][0-9]:[012345][0-9] GMT|(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun) (?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) (?:[ 1-2][0-9]|3[01]) (?:[01][0-9]|2[0-3]):[012345][0-9]:[012345][0-9] \d{4})
https://snipt.net/embed/34a920c3bd75951b7aa4aff6c40a9f28/
/raw/34a920c3bd75951b7aa4aff6c40a9f28/
34a920c3bd75951b7aa4aff6c40a9f28
text
Text only
1
2019-07-17T08:21:11
True
False
False
Apr 03, 2015 at 04:33 PM
/api/public/snipt/138884/
http-date-regular-expression-validation-rfc-1123rfc-850asctime-f64e6aa3
<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>(?:(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun), (?:[0-2][0-9]|3[01]) (?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \d{4} (?:[01][0-9]|2[0-3]):[012345][0-9]:[012345][0-9] GMT|(?:Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday), (?:[0-2][0-9]|3[01])-(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)-\d{2} (?:[01][0-9]|2[0-3]):[012345][0-9]:[012345][0-9] GMT|(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun) (?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) (?:[ 1-2][0-9]|3[01]) (?:[01][0-9]|2[0-3]):[012345][0-9]:[012345][0-9] \d{4}) </span></pre></div> </td></tr></table>
"ANSI C", "RFC 1123", "RFC 2616", "RFC 850", 1123, 2616, 850, Date, HTTP, HTTP-Date, HTTP/1.1, RFC, asctime, expression, format, regular, validation

Text only

RFC 1123 regular expression validation

(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun), (?:[0-2][0-9]|3[01]) (?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \d{4} (?:[01][0-9]|2[0-3]):[012345][0-9]:[012345][0-9] GMT
https://snipt.net/embed/eecad054c520ad40fa0ebef8843e2f90/
/raw/eecad054c520ad40fa0ebef8843e2f90/
eecad054c520ad40fa0ebef8843e2f90
text
Text only
1
2019-07-19T06:51:47
True
False
False
/api/public/snipt/138883/
rfc-1123-regular-expression-validation-f4262fe2
<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>(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun), (?:[0-2][0-9]|3[01]) (?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \d{4} (?:[01][0-9]|2[0-3]):[012345][0-9]:[012345][0-9] GMT </span></pre></div> </td></tr></table>
"RFC 1123", 1123, Date, RFC, expression, regular, validation

JavaScript

JS Date formatter

1
2
3
4
5
6
7
/*
 * Función formateadora de fechas.
 */
function dateFormatter(dateAsLong) {
	var date = new Date(dateAsLong);
	return date.getDate() + "/" + (date.getMonth() + 1) + "/" + date.getFullYear() + " " + date.getHours() + ":" + date.getMinutes();
}
https://snipt.net/embed/878440b0b9c96f05a6fad01f29bf24cf/
/raw/878440b0b9c96f05a6fad01f29bf24cf/
878440b0b9c96f05a6fad01f29bf24cf
js
JavaScript
7
2019-07-20T21:09:37
True
False
False
May 05, 2014 at 05:38 AM
/api/public/snipt/134736/
js-date-formatter-9e1198a7
<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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="cm">/*</span> </span><span id="L-2"><a name="L-2"></a><span class="cm"> * Función formateadora de fechas.</span> </span><span id="L-3"><a name="L-3"></a><span class="cm"> */</span> </span><span id="L-4"><a name="L-4"></a><span class="kd">function</span> <span class="nx">dateFormatter</span><span class="p">(</span><span class="nx">dateAsLong</span><span class="p">)</span> <span class="p">{</span> </span><span id="L-5"><a name="L-5"></a> <span class="kd">var</span> <span class="nx">date</span> <span class="o">=</span> <span class="k">new</span> <span class="nb">Date</span><span class="p">(</span><span class="nx">dateAsLong</span><span class="p">);</span> </span><span id="L-6"><a name="L-6"></a> <span class="k">return</span> <span class="nx">date</span><span class="p">.</span><span class="nx">getDate</span><span class="p">()</span> <span class="o">+</span> <span class="s2">&quot;/&quot;</span> <span class="o">+</span> <span class="p">(</span><span class="nx">date</span><span class="p">.</span><span class="nx">getMonth</span><span class="p">()</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot;/&quot;</span> <span class="o">+</span> <span class="nx">date</span><span class="p">.</span><span class="nx">getFullYear</span><span class="p">()</span> <span class="o">+</span> <span class="s2">&quot; &quot;</span> <span class="o">+</span> <span class="nx">date</span><span class="p">.</span><span class="nx">getHours</span><span class="p">()</span> <span class="o">+</span> <span class="s2">&quot;:&quot;</span> <span class="o">+</span> <span class="nx">date</span><span class="p">.</span><span class="nx">getMinutes</span><span class="p">();</span> </span><span id="L-7"><a name="L-7"></a><span class="p">}</span> </span></pre></div> </td></tr></table>
Date, JS, format

PHP

PHP Date triggered events

1
2
3
4
5
6
<?
$time_passed = (time() > strtotime('2014-01-18 00:00:00'));
    
    if ($time_passed) {
        // Do something
    } ?>
https://snipt.net/embed/8025a38e4bb59287149635f0207a45b6/
/raw/8025a38e4bb59287149635f0207a45b6/
8025a38e4bb59287149635f0207a45b6
php
PHP
6
2019-07-07T02:51:56
True
False
False
Apr 03, 2014 at 11:33 PM
/api/public/snipt/105446/
php-date-triggered-events
<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="cp">&lt;?</span> </span><span id="L-2"><a name="L-2"></a><span class="nv">$time_passed</span> <span class="o">=</span> <span class="p">(</span><span class="nb">time</span><span class="p">()</span> <span class="o">&gt;</span> <span class="nb">strtotime</span><span class="p">(</span><span class="s1">&#39;2014-01-18 00:00:00&#39;</span><span class="p">));</span> </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a> <span class="k">if</span> <span class="p">(</span><span class="nv">$time_passed</span><span class="p">)</span> <span class="p">{</span> </span><span id="L-5"><a name="L-5"></a> <span class="c1">// Do something</span> </span><span id="L-6"><a name="L-6"></a> <span class="p">}</span> <span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
Date, PHP