Repository: spyder-ide/spyder

Issue:
Editing or viewing a datetime looses miliseconds part of the datetime timestamp
<!--- **PLEASE READ:** When submitting here, please ensure you've completed the following checklist and checked the boxes to confirm. Issue reports without it may be closed. Thanks! --->

### Issue Report Checklist

* [x] Searched the [issues page](https://github.com/spyder-ide/spyder/issues?q=is%3Aissue) for similar reports
* [x] Read the relevant sections of the [Spyder Troubleshooting Guide](https://github.com/spyder-ide/spyder/wiki/Troubleshooting-Guide-and-FAQ) and followed its advice
* [x] Reproduced the issue after updating with ``conda update spyder`` (or ``pip``, if not using Anaconda)
* [ ] Could not reproduce inside ``jupyter qtconsole`` (if console-related)
* [x] Tried basic troubleshooting (if a bug/error)
    * [x] Restarted Spyder
    * [ ] Reset preferences with ``spyder --reset``
    * [ ] Reinstalled the latest version of [Anaconda](https://www.anaconda.com/download/)
    * [ ] Tried the other applicable steps from the Troubleshooting Guide
* [x] Completed the **Problem Description**, **Steps to Reproduce** and **Version** sections below


## Problem Description
Editing/clicking on a variable of type 'datetime' in the variable explorer looses the milisecond part of the datetime variable.


### What steps reproduce the problem?

1.  Create a test datetime variable
```
import datetime
test = datetime.datetime.strptime('2019-05-21 14:50:07.125', '%Y-%m-%d %H:%M:%S.%f')
```
2. Print out this variable
```
print(test)
```
2019-05-21 14:50:07.125000

3. Double click on this variable in the variable explorer
4. Print out the variable again
```
print(test)
```
2019-05-21 14:50:07

### What is the expected output? What do you see instead?
I assume this behavior is not intentional, the variable should not loose the precision of the millisecond parts of the datetime object when double clicking it in the variable explorer?


## Versions
<!--- You can get this information from Help > About Spyder...
or (if Spyder won't launch) the "conda list" command
from the Anaconda Prompt/Terminal/command line. --->

* Spyder version: 3.3.3
* Python version: 3.7.3
* Qt version: 5.9.6
* PyQt version: 5.9.2
* Operating System name/version: Windows 10 Enterprise 64-bit

### Dependencies
<!--- Please go to the menu entry Help > Dependencies,
press the Copy to clipboard button and paste below --->

```
IPython >=4.0     :  7.4.0 (OK)
cython >=0.21     :  0.29.6 (OK)
jedi >=0.9.0      :  0.13.3 (OK)
matplotlib >=2.0.0:  3.0.3 (OK)
nbconvert >=4.0   :  5.4.1 (OK)
numpy >=1.7       :  1.16.2 (OK)
pandas >=0.13.1   :  0.24.2 (OK)
pycodestyle >=2.3 :  2.5.0 (OK)
pyflakes >=0.6.0  :  2.1.1 (OK)
pygments >=2.0    :  2.3.1 (OK)
pylint >=0.25     :  2.3.1 (OK)
qtconsole >=4.2.0 :  4.4.3 (OK)
rope >=0.9.4      :  0.12.0 (OK)
sphinx >=0.6.6    :  1.8.5 (OK)
sympy >=0.7.3     :  1.3 (OK)

```



Discussion:
Thanks for reporting. We'll try to take a look at this for Spyder 4.

Resolving patch:
diff --git a/spyder/plugins/variableexplorer/widgets/collectionseditor.py b/spyder/plugins/variableexplorer/widgets/collectionseditor.py
--- a/spyder/plugins/variableexplorer/widgets/collectionseditor.py
+++ b/spyder/plugins/variableexplorer/widgets/collectionseditor.py
@@ -536,6 +536,7 @@ def createEditor(self, parent, option, index, object_explorer=False):
             else:
                 if isinstance(value, datetime.datetime):
                     editor = QDateTimeEdit(value, parent=parent)
+                    editor.setDisplayFormat('dd/MM/yyyy HH:mm:ss.zzz')
                 else:
                     editor = QDateEdit(value, parent=parent)
                 editor.setCalendarPopup(True)
@@ -698,14 +699,15 @@ def setModelData(self, editor, model, index):
                 return
         elif isinstance(editor, QDateEdit):
             qdate = editor.date()
-            value = datetime.date( qdate.year(), qdate.month(), qdate.day() )
+            value = datetime.date(qdate.year(), qdate.month(), qdate.day())
         elif isinstance(editor, QDateTimeEdit):
             qdatetime = editor.dateTime()
             qdate = qdatetime.date()
             qtime = qdatetime.time()
-            value = datetime.datetime( qdate.year(), qdate.month(),
-                                       qdate.day(), qtime.hour(),
-                                       qtime.minute(), qtime.second() )
+            # datetime uses microseconds, QDateTime returns milliseconds
+            value = datetime.datetime(qdate.year(), qdate.month(), qdate.day(),
+                                      qtime.hour(), qtime.minute(),
+                                      qtime.second(), qtime.msec()*1000)
         else:
             # Should not happen...
             raise RuntimeError("Unsupported editor widget")


Test patch: