Skip to content

Instantly share code, notes, and snippets.

@bmorris3
Created November 4, 2015 23:44
Show Gist options
  • Save bmorris3/94697b0f1e65a3ab29c6 to your computer and use it in GitHub Desktop.
Save bmorris3/94697b0f1e65a3ab29c6 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"datetime.datetime(2015, 1, 10, 2, 5, 10)"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import datetime\n",
"import pytz\n",
"\n",
"# define a naive datetime: \n",
"d1 = datetime.datetime(2015, 1, 10, 2, 5, 10)\n",
"d1"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"datetime.datetime(2015, 1, 10, 2, 5, 10, tzinfo=<DstTzInfo 'US/Hawaii' LMT-1 day, 13:29:00 STD>)"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# \"aware\" datetime\n",
"tz = pytz.timezone(\"US/Hawaii\")\n",
"d2 = datetime.datetime(2015, 1, 10, 2, 5, 10, tzinfo=tz)\n",
"d2"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"utc = pytz.timezone('UTC')\n",
"\n",
"d3 = utc.normalize(d2)"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"datetime.time(12, 36, 10)"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"d3.time()"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"d2 == d3"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.10"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment