# Printing now(), different output, I am confused

**URL:** <https://forum.inductiveautomation.com/t/printing-now-different-output-i-am-confused/83341>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [December 20, 2023, 3:24am UTC](https://forum.inductiveautomation.com/t/printing-now-different-output-i-am-confused/83341 "2023-12-20T03:24:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eugene49](https://avatars.discourse-cdn.com/v4/letter/e/c6cbf5/32.png) [@Eugene49](https://forum.inductiveautomation.com/u/Eugene49)\
**Post date:** [December 20, 2023, 3:24am UTC](https://forum.inductiveautomation.com/t/printing-now-different-output-i-am-confused/83341/1 "2023-12-20T03:24:14Z")

</div>

So I am processing and printing time.

Depending on where I use it, output is different.

I want to understand what is the general rule, so I can code properly.

below is what I experienced:

```auto
	timeNow = system.date.now()
	
	#passing to label
	self.getSibling("Label").props.text = timeNow
	#output: "2023-12-20T03:09:27.322Z"
	
	#passing to console
	system.perspective.print(timeNow)
	#output: 2023-12-19 21:09:27.322
	
	#passing to dataset, render=date
	headers = ['timeNow']
	rows = [[timeNow]]
	ds = system.dataset.toDataSet(headers, rows)
	self.getSibling("Table").props.data = ds
	#output: 12/20/2023 11:09:27

```

how did dataset display as `12/20/2023 11:09:27`

Why even the label component displays double quote? hmm..

---

<div class="post-metadata">

**Author:** ![MSviga](https://avatars.discourse-cdn.com/v4/letter/m/3e96dc/32.png) [@MSviga](https://forum.inductiveautomation.com/u/MSviga)\
**Post date:** [December 20, 2023, 6:34am UTC](https://forum.inductiveautomation.com/t/printing-now-different-output-i-am-confused/83341/2 "2023-12-20T06:34:41Z")

</div>

So I tried recreating what you are seeing. Using the `type()` function to check if something funky is going on with data types in the background I found out the underlying data always stays a java.util.date.

My guess is that how ignition handles displaying a java.util.date object in different components is inconsistent. You have a few ways of making sure you are displaying date time objects like you want, for example in the expression language `dateFormat()` and in the scripting library `system.date.format`.

On a side note, casting a java.util.date to a string using `str()` yields a decent result such as "Wed Dec 20 07:23:51 CET 2023"

---

<div class="post-metadata">

**Author:** ![louagejasper](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/louagejasper/32/86311_2.png) [@louagejasper](https://forum.inductiveautomation.com/u/louagejasper)\
**Post date:** [December 20, 2023, 8:01am UTC](https://forum.inductiveautomation.com/t/printing-now-different-output-i-am-confused/83341/3 "2023-12-20T08:01:21Z")

</div>

Fyi, it's nothing to do with datasets. If I run this in the script console, I get two dates that are equal:

```auto
timeNow = system.date.now()

print timeNow
#output: Wed Dec 20 08:57:44 CET 2023

#passing to dataset
headers = ['timeNow']
rows = [[timeNow]]
ds = system.dataset.toDataSet(headers, rows)

print ds.getValueAt(0,0)
#output: Wed Dec 20 08:57:44 CET 2023

```

Could it not have something to do with time zones? Since you are going back and forth between Perspective and the script?

---

<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:** [December 20, 2023, 11:53am UTC](https://forum.inductiveautomation.com/t/printing-now-different-output-i-am-confused/83341/4 "2023-12-20T11:53:44Z")

</div>

You get the timezone that applies at the point where the `java.util.Date`, which is itself purely UTC, is converted to a string. If in the gateway process, it will be the gateway's time zone. If in the designer (like the tag browser), it will be the designer's time zone. If in the perspective client using a native component's date formatting, it will be the session time zone. Perspective scripts and expressions run in the gateway. If you want those to use the session timezone, you have to apply it yourself, with Java.

This topic should help:

> [@Ignition Perspective Page to show the client System date and time](https://forum.inductiveautomation.com/t/ignition-perspective-page-to-show-the-client-system-date-and-time/73265/8):
>
> Sure. I recommend [DateTimeFormatter.ofPattern()](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/time/format/DateTimeFormatter.html#ofPattern(java.lang.String)). But I would move the complexity to a project script module with a DateTimeFormatter instance with your preferred pattern saved as a top level variable. Like so, perhaps: from java.time import ZoneId from java.time.format import DateTimeFormatter defaultFormatter = DateTimeFormatter.ofPattern("YYYY-MM-dd HH:mm") def zonedFormat(ts, zoneid, format=None): formatter = defaultFormatter if format is None else DateTimeFormatter.ofPattern(format) r…

{ Read the whole thing. }

---

<div class="post-metadata">

**Author:** ![Eugene49](https://avatars.discourse-cdn.com/v4/letter/e/c6cbf5/32.png) [@Eugene49](https://forum.inductiveautomation.com/u/Eugene49)\
**Post date:** [December 20, 2023, 4:27pm UTC](https://forum.inductiveautomation.com/t/printing-now-different-output-i-am-confused/83341/5 "2023-12-20T16:27:22Z")

</div>

Still confusing...  
For education purpose,  
I set gateway timezone, project timezone, client timezone, to different timezone.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/2/a27cecbdcbc31be240116d5361eb55d8179b2bc3.png)

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/4/d46ebeae07a531e59e0f736842f89a25000f03c9.png)

Conclusion:  
`system.date.now()` will assign UTC String

`system.date.format()` will do two things, UTC Time with gatewayOffset

Table component - will render UTC string to integer with "project time" offset

To get Client's time: I need to:

```auto
	#client time
	timeNow = system.date.now()
	
	deviceUtcOffset = self.session.props.device.timezone.utcOffset
	gatewayUtcOffset = self.session.props.gateway.timezone.utcOffset
	
	offset = deviceUtcOffset - gatewayUtcOffset 
	
	#client time in UTC string with client offset
	clientTime = system.date.addHours(timeNow, offset)
	
	#apply date format (apply gateway offset and format it)
	clientTimeFormated = system.date.format(clientTime, "yyyy-MM-dd hh:mm:ss a")
	
	return clientTimeFormated

```

---

<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:** [December 20, 2023, 5:38pm UTC](https://forum.inductiveautomation.com/t/printing-now-different-output-i-am-confused/83341/6 "2023-12-20T17:38:09Z")

</div>

> [@Eugene49](#):
>
> Conclusion:  
> `system.date.now()` will assign UTC String

No, it does not. It returns a `java.util.Date` object. _ **Not a string** _. Printing or logging it turns it into a string, for that purpose, _ **at that point in your code** _.

> [@Eugene49](#):
>
> `clientTime = system.date.addHours(timeNow, offset)`

Don't do this. Don't use date arithmetic to "fix" timezoneless date objects. Use zoned date formatting, as shown in the linked topic.

> [@Eugene49](#):
>
> `clientTimeFormated = system.date.format(`

Don't use `system.date.format()` when trying to use a non-default time zone (non-default for the context the code runs in). Use zoned date formatting, as shown in the linked topic.

Don't print date/time objects, in general, unless you know the context they are in.
