Login

Converting datetime to Javascript milliseconds in epoch

Author:
guychi
Posted:
August 25, 2007
Language:
Python
Version:
.96
Score:
2 (after 2 ratings)

Useful for transferring datetime values to JS: briefer and overcoming the 1 vs. 0 based month enumeration difference between python and JS.

1
2
3
4
from time import mktime

def datetime_to_ms_str(dt):
    return str(1000*mktime(dt.timetuple()))

More like this

  1. LazyPrimaryKeyRelatedField by LLyaudet 6 days, 4 hours ago
  2. CacheInDictManager by LLyaudet 6 days, 11 hours ago
  3. MYSQL Full Text Expression by Bidaya0 1 week ago
  4. Custom model manager chaining (Python 3 re-write) by Spotted1270 1 week, 6 days ago
  5. Django Standard API Response Middleware for DRF for modern frontend easy usage by Denactive 4 weeks, 1 day ago

Comments

Please login first before commenting.