# File Timestamp wrong when writing it to DateTime Tag

**URL:** <https://forum.inductiveautomation.com/t/file-timestamp-wrong-when-writing-it-to-datetime-tag/29063>\
**Category:** Ignition\
**Tags:** ignition80\
**Created:** [October 14, 2019, 10:14am UTC](https://forum.inductiveautomation.com/t/file-timestamp-wrong-when-writing-it-to-datetime-tag/29063 "2019-10-14T10:14:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![zxcslo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zxcslo/32/61610_2.png) [@zxcslo](https://forum.inductiveautomation.com/u/zxcslo)\
**Post date:** [October 14, 2019, 10:14am UTC](https://forum.inductiveautomation.com/t/file-timestamp-wrong-when-writing-it-to-datetime-tag/29063/1 "2019-10-14T10:14:56Z")

</div>

Can somebody explain this to me: 🤔

 ![Screenshot_3](https://us1.discourse-cdn.com/inductiveautomation/original/2X/a/ad61b55ffac98147b7289b69985faaf458ecda8a.png)  
I read the time of the last modification of the file and write it to the DateTime Memory Tag.  
But the value in the tag is wrong. It is two hours ahead… Why?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [October 14, 2019, 11:38am UTC](https://forum.inductiveautomation.com/t/file-timestamp-wrong-when-writing-it-to-datetime-tag/29063/2 "2019-10-14T11:38:07Z")

</div>

Try with Java’s File object and related infrastructure.

---

<div class="post-metadata">

**Author:** ![zxcslo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zxcslo/32/61610_2.png) [@zxcslo](https://forum.inductiveautomation.com/u/zxcslo)\
**Post date:** [October 14, 2019, 12:14pm UTC](https://forum.inductiveautomation.com/t/file-timestamp-wrong-when-writing-it-to-datetime-tag/29063/3 "2019-10-14T12:14:27Z")

</div>

Thanks, @pturmel.  
I ended up with this:

```auto
import os
import datetime
from java.io import File
from java.text import SimpleDateFormat

path = "c:\\temp\\test\\wrapper.log"
logfile = File(path)
t = logfile.lastModified()
print "t:", 
sdf = SimpleDateFormat("MM/dd/yyyy HH:mm:ss")
modified = sdf.format(t)
print "modified: ", modified
path = ["[realtimeBulky1]datetime"]
value = [modified]
system.tag.writeBlocking(path, value)

```

Now the tag value it’s OK.  
But I still don’t understand why…?

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [October 14, 2019, 12:21pm UTC](https://forum.inductiveautomation.com/t/file-timestamp-wrong-when-writing-it-to-datetime-tag/29063/4 "2019-10-14T12:21:07Z")

</div>

It’s because _fromtimestamp()_ returns None for the timezone in the datetime object.

You can also write the timestamp in millis directly to your tag.

```python
import os

path = 'C:/path/to/file'

# Get modified time of the file in milliseconds
t = long(os.path.getmtime(path)) * 1000

tagPath = ['[default]Test/datetime']
value = [t]

system.tag.writeBlocking(tagPath, value)

```

---

<div class="post-metadata">

**Author:** ![zxcslo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zxcslo/32/61610_2.png) [@zxcslo](https://forum.inductiveautomation.com/u/zxcslo)\
**Post date:** [October 14, 2019, 12:31pm UTC](https://forum.inductiveautomation.com/t/file-timestamp-wrong-when-writing-it-to-datetime-tag/29063/5 "2019-10-14T12:31:14Z")

</div>

Very good, @JordanCClark.  
I ended up with your ‘solution’… 👍
