Avatar

Please consider registering
guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed Topic RSS sp_TopicIcon
cannot set DateTime variable
July 17, 2017
18:05, EEST
Avatar
ibrahim
Member
Members
Forum Posts: 75
Member Since:
August 20, 2014
sp_UserOfflineSmall Offline

Hi,
i was doing some tests with an OPC UA Server and variables. I tried to set a DateTime variable, but i’m not able to do it. I want to initialize the variable with e.g. the date: Wednesday, 12. July 2017 09:37:27.995, which is in ms: 1499852247995.
This is the code to initialize the variable:

CacheVariable dateTime = new CacheVariable(this, new NodeId(2, “DateTimeId”),”DateTime”, LocalizedText.NO_LOCALE);
dateTime.setDataType(getServer().getNodeManagerRoot().getType(Identifiers.DateTime));
long date = 1499852247995L;
dateTime.setValue(new DataValue(new Variant(new DateTime(date))));
methodsFolder.addComponent(dateTime);

if i start the server and take a look at this variabel i see the follwoing date:
2000-01-01T00:00:00.000Z

what is wrong with my code?

Thanks.

Ibrahim

July 17, 2017
18:40, EEST
Avatar
Jouni Aro
Moderator
Moderators
Forum Posts: 1009
Member Since:
December 21, 2011
sp_UserOfflineSmall Offline

The constructor is not expecting milliseconds.

/**
* Constructs a new DateTime value, initializing it with an OPC UA time value with a resolution of 100 nanoseconds.
*/
public DateTime(long value);

Instead, you should use ‘DateTime dt = DateTime.fromMillis(date);’, if you want to initialise it from milliseconds.

July 18, 2017
10:21, EEST
Avatar
ibrahim
Member
Members
Forum Posts: 75
Member Since:
August 20, 2014
sp_UserOfflineSmall Offline

Hi,
thanks Jouni, i should have read the java doc. Now it works…
Thanks

Ibrahim

July 18, 2017
14:32, EEST
Avatar
Jouni Aro
Moderator
Moderators
Forum Posts: 1009
Member Since:
December 21, 2011
sp_UserOfflineSmall Offline

NP. It’s not very intuitive…

Forum Timezone: Europe/Helsinki

Most Users Ever Online: 518

Currently Online:
19 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

hbrackel: 135

pramanj: 86

Francesco Zambon: 81

ibrahim: 75

rocket science: 75

Sabari: 62

kapsl: 57

gjevremovic: 49

Xavier: 43

fred: 41

Member Stats:

Guest Posters: 0

Members: 707

Moderators: 16

Admins: 1

Forum Stats:

Groups: 3

Forums: 15

Topics: 1465

Posts: 6252

Newest Members:

christi10l, ahamad1, Flores Frederick, ellenmoss, harriettscherer, shanonhumphreys, KupimotoblokfuB, tamhollander5, paulinafcf, bridgette18l

Moderators: Jouni Aro: 1009, Otso Palonen: 32, Tuomas Hiltunen: 5, Pyry: 1, Petri: 0, Bjarne Boström: 982, Heikki Tahvanainen: 402, Jukka Asikainen: 1, moldzh08: 0, Jimmy Ni: 26, Teppo Uimonen: 21, Markus Johansson: 42, Niklas Nurminen: 0, Matti Siponen: 319, Lusetti: 0, Ari-Pekka Soikkeli: 5

Administrators: admin: 1