Skip to content

Instantly share code, notes, and snippets.

@dudarev
Created January 7, 2019 12:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dudarev/33dce61a754a39fbadd9c493ed25cb96 to your computer and use it in GitHub Desktop.
Save dudarev/33dce61a754a39fbadd9c493ed25cb96 to your computer and use it in GitHub Desktop.
Strip timezones
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from datetime import datetime"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"TIMEZONES_TO_STRIP = [\"EDT\", \"EST\"]"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'09-Oct-2018 07:54 PM'"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"value = \"09-Oct-2018 07:54 PM EDT\"\n",
"for tz in TIMEZONES_TO_STRIP:\n",
" value = value.replace(tz, '').strip()\n",
"value"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"datetime.datetime(2018, 10, 9, 19, 54)"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"tx_datetime = datetime.strptime(value, \"%d-%b-%Y %I:%M %p\")\n",
"tx_datetime"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.8"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment