python datetime to float with millisecond precision
<p>What is a classy way to store date and time information in a float in python with millisecond precision?
Edit: I'm using python 2.7</p>

<p>I've hacked together the following:</p>

<pre><code>DT = datetime.datetime(2016,01,30,15,16,19,234000) #trailing zeros are required
DN = (DT - datetime.datetime(2000,1,1)).total_seconds()
print repr(DN)
</code></pre>

<p>Output:</p>

<pre><code>507482179.234
</code></pre>

<p>And then to revert back to datetime:</p>

<pre><code>DT2 = datetime.datetime(2000,1,1) + datetime.timedelta(0, DN)
print DT2
</code></pre>

<p>Output:</p>

<pre><code>2016-01-30 15:16:19.234000
</code></pre>

<p>But I'm really looking for something a little more classy and robust.</p>

<p>In matlab I would use the <code>datenum</code> and <code>datetime</code> functions:</p>

<pre><code>DN = datenum(datetime(2016,01,30,15,16,19.234))
</code></pre>

<p>And to revert back:</p>

<pre><code>DT = datetime(DN,'ConvertFrom','datenum')
</code></pre>