snipt

Ctrl+h for KB shortcuts

SQL

Get timezone

SELECT @@global.time_zone, @@session.time_zone;
https://snipt.net/embed/43b0853fff8e83739106df56b90a1356/
https://snipt.net/raw/43b0853fff8e83739106df56b90a1356/
43b0853fff8e83739106df56b90a1356
sql
SQL
1
2016-09-30T10:04:55
True
False
False
Nov 14, 2012 at 10:00 PM
/api/public/snipt/50257/
get-timezone
<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 id="L-1"><a name="L-1"></a><span class="k">SELECT</span> <span class="o">@@</span><span class="k">global</span><span class="p">.</span><span class="n">time_zone</span><span class="p">,</span> <span class="o">@@</span><span class="k">session</span><span class="p">.</span><span class="n">time_zone</span><span class="p">;</span> </span></pre></div> </td></tr></table>
sql, timezone

SQL

Set timezone

set time_zone = '+00:00';
https://snipt.net/embed/248521bddd542e10e93ac9ba1769446c/
https://snipt.net/raw/248521bddd542e10e93ac9ba1769446c/
248521bddd542e10e93ac9ba1769446c
sql
SQL
1
2016-09-30T10:05:05
True
False
False
Nov 14, 2012 at 09:55 PM
/api/public/snipt/50255/
set-timezone
<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 id="L-1"><a name="L-1"></a><span class="k">set</span> <span class="n">time_zone</span> <span class="o">=</span> <span class="s1">&#39;+00:00&#39;</span><span class="p">;</span> </span></pre></div> </td></tr></table>
sql, timezone

PHP

Get timezone offset

1
2
3
4
5
6
<?php
if(!isset($timezone)) $timezone="Europe/Paris";
$tz = new DateTimeZone($timezone);
$offset = $tz->getOffset(new DateTime("now")); // Offset in seconds
echo ($offset < 0 ? '-' : '+').round($offset/3600); // prints "+1"
?>
https://snipt.net/embed/ad3a1d8d1593453081058e1bbc982c93/
https://snipt.net/raw/ad3a1d8d1593453081058e1bbc982c93/
ad3a1d8d1593453081058e1bbc982c93
php
PHP
6
2016-08-02T12:48:06
True
False
False
/api/public/snipt/20599/
get-timezone-offset
<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 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 class="k">if</span><span class="p">(</span><span class="o">!</span><span class="nb">isset</span><span class="p">(</span><span class="nv">$timezone</span><span class="p">))</span> <span class="nv">$timezone</span><span class="o">=</span><span class="s2">&quot;Europe/Paris&quot;</span><span class="p">;</span> </span><span id="L-3"><a name="L-3"></a><span class="nv">$tz</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">DateTimeZone</span><span class="p">(</span><span class="nv">$timezone</span><span class="p">);</span> </span><span id="L-4"><a name="L-4"></a><span class="nv">$offset</span> <span class="o">=</span> <span class="nv">$tz</span><span class="o">-&gt;</span><span class="na">getOffset</span><span class="p">(</span><span class="k">new</span> <span class="nx">DateTime</span><span class="p">(</span><span class="s2">&quot;now&quot;</span><span class="p">));</span> <span class="c1">// Offset in seconds</span> </span><span id="L-5"><a name="L-5"></a><span class="k">echo</span> <span class="p">(</span><span class="nv">$offset</span> <span class="o">&lt;</span> <span class="mi">0</span> <span class="o">?</span> <span class="s1">&#39;-&#39;</span> <span class="o">:</span> <span class="s1">&#39;+&#39;</span><span class="p">)</span><span class="o">.</span><span class="nb">round</span><span class="p">(</span><span class="nv">$offset</span><span class="o">/</span><span class="mi">3600</span><span class="p">);</span> <span class="c1">// prints &quot;+1&quot;</span> </span><span id="L-6"><a name="L-6"></a><span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
php, timezone, web

PHP

PHP timezone conversion in one line

echo date_create($userDate)->setTimezone(new DateTimeZone($userTimezone))->format(‘Y-m-d H:i’);
https://snipt.net/embed/ed38aeb4d135e83f4509982bc13ab8e9/
https://snipt.net/raw/ed38aeb4d135e83f4509982bc13ab8e9/
ed38aeb4d135e83f4509982bc13ab8e9
php
PHP
1
2016-09-29T02:43:35
True
False
False
/api/public/snipt/17200/
timezone-conversion-from-servers-timezone-to-users-in-one-line
<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 id="L-1"><a name="L-1"></a><span class="x">echo date_create($userDate)-&gt;setTimezone(new DateTimeZone($userTimezone))-&gt;format(‘Y-m-d H:i’);</span> </span></pre></div> </td></tr></table>
conversion, php, time, timezone

PHP

Set the time zone in php

date_default_timezone_set('Asia/Singapore')
https://snipt.net/embed/d4f6ea2e75b4bf9ec7d21885c0e4c5fb/
https://snipt.net/raw/d4f6ea2e75b4bf9ec7d21885c0e4c5fb/
d4f6ea2e75b4bf9ec7d21885c0e4c5fb
php
PHP
1
2016-09-30T18:38:39
True
False
False
/api/public/snipt/5318/
set-the-time-zone-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 id="L-1"><a name="L-1"></a><span class="x">date_default_timezone_set(&#39;Asia/Singapore&#39;)</span> </span></pre></div> </td></tr></table>
php, timezone

Bash

set timezone on ubuntu intrepid

sudo dpkg-reconfigure tzdata
https://snipt.net/embed/169ee19a7a9924b1dd7c14c27d7b4e3c/
https://snipt.net/raw/169ee19a7a9924b1dd7c14c27d7b4e3c/
169ee19a7a9924b1dd7c14c27d7b4e3c
bash
Bash
1
2016-09-29T13:28:06
True
False
False
/api/public/snipt/3702/
set-timezone-on-ubuntu-intrepid
<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 id="L-1"><a name="L-1"></a>sudo dpkg-reconfigure tzdata </span></pre></div> </td></tr></table>
timezone, ubuntu, unix
Copyrighted, illegal, or inappropriate content? Email support@snipt.net.