Hi, this worked for me with a PC Runtime. But now I ma using a MTP700. I copied/pasted this field in my MTP700 project and it doesn't work. The Time and date are freezed to the default value I have put (00:00 and 01/01/1970) I checked that the script is triggered every second. Any idea ?
@@umachado I should post it earlier. I asked the hotline and they answered me that there is a bug. Here is the answer translated (i am from France): Local Time : Correct the script like this ('hr-HR',) => don’t forget the coma let myLocal = myDate.toLocaleTimeString('hr-HR',); And don’t put display format for the field I didn’t test it because i finally use date and time together (in the same field and it works)
Hi, I have a start & stop timestamp (DateTime format) but I want to display actual machine run hours that need to subtract from (start time - stop time). So how to subtract the DateTime format? Ex : (2022-02-17 12:45:41.960) - (2022-02-18 12:48:41.960) = 24.56 (Start Timestamp) - (Stop Timestamp) = Actual Run Hours
Hi, I would split it. With this Math funtion you get the difference in milliseconds let difference= Math.abs(day2-day1); let Days = difference/(1000 * 3600 * 24) let Hours = difference/(1000 * 3600 ) let Minutes= difference/(1000 * 60) here you will find different solutions stackoverflow.com/questions/3224834/get-difference-between-2-dates-in-javascript
@@DerHecht40 My Script is: export function EA_Feld_1_ProcessValue_Trigger(item) { let myDate = new Date(); let myLocalDate = myDate.toLocaleSting(); return myLocalDate; } But I've tried the exact same you did. I think it has something to do with the trigger? Trigger is T1S
I did exactly as you explained, however I am using a button that sends the information to the TAG and this tab is displayed in an IO Field, however when I put the myLocal variable to write nothing happens export function Button_1_OnTapped(item, x, y, modifiers, trigger) { var value; let myDate = new Date(); let myLocal = myDate.toLocaleTimeString(); value = myLocal; HMIRuntime.Tags.SysFct.SetTagValue("dataInicio", value); }
Hi, via Java Script or where did you want to display it? const date = new Date(); const hours = date.getHours(); // current hours in 24-hour format const minutes = date.getMinutes(); let ampm = hours >= 12 ? 'PM' : 'AM'; // determine whether to use AM or PM hours = hours % 12; // convert to 12-hour format hours = hours ? hours : 12; // use 12 if hours is 0 const formattedTime = hours + ':' + minutes + ' ' + ampm; // time in 12-hour format
This does not work the same when I try it. The value displayed for local date and time is incorrect. It's as if the toLocaleString() value is converted back to UTC by the IO Field control object.
Yes, I had the output format defined to display the time in the way I wanted. It does show the correct time without the formatting, which is very disappointing. The entire advantage of the IO field control vs textbox control in this case is the formatting.
@@DerHecht40 The output format makes it easy to produce a detailed display of date and time (e.g. October 30, 2020 11:59:59 PM). To produce that same format with JavaScript is a bit involved for what is supposed to be a short routine executed every second.
Hi There, so the local date and time setting works so far as String. But i need the time and date seperatly in a I/O field. Do you know, how i can solve the requirement? things that i allready tried :1. I/O Field format into Date or Time 2. (tried) to changed the script (its tricky, without a console or syntax check it worked better befor with VBS and C). It's really anoying because you have to try it again and again and the reloading needs a lot of time... i also have a problem to read and write HMI Tags into I/O fields maybe it's possible to get a extra video oh them? i used the "snippets" but my I/O Fields are always filled with the start values. It doesn't make a difference to tap a button or not.
Okay i figured it out. If someone need : var Value let myDate = new Date(); let myLocal = myDate.toLocaleTimeString('de-DE'); Value = myLocal; return(Value);
@@benjaminhaus8054 It's ok, i already found it. To anyone who need it. for time: let myLocal = myDate.toLocaleTimeString('de-DE'); for date: let myLocal = myDate.toLocaleDateString('de-DE');
@@hafizahmad3597 in my case i written :" var Value let myDate = New Date(); Value = myDate; return(Value); And i formated the IO Field into {D,@dd.MM.yyyy} have a nice day!
@@DerHecht40 OK, thx. Ich use now another solution. I use this ntp Server function from Siemens to set the Panel by PLC and i also send the timediference from Panel to PLC to set the localtime in PLC.
Hi, this worked for me with a PC Runtime. But now I ma using a MTP700. I copied/pasted this field in my MTP700 project and it doesn't work. The Time and date are freezed to the default value I have put (00:00 and 01/01/1970) I checked that the script is triggered every second. Any idea ?
I'm having the same problema. The problem started after updating the OS to version 5.
@@umachado
I should post it earlier. I asked the hotline and they answered me that there is a bug.
Here is the answer translated (i am from France):
Local Time :
Correct the script like this ('hr-HR',) => don’t forget the coma
let myLocal = myDate.toLocaleTimeString('hr-HR',);
And don’t put display format for the field
I didn’t test it because i finally use date and time together (in the same field and it works)
@@mehdiaidel4547 Thank you for the help. I tried to remove the format of the field an then it worked.
@@umachado great !
You are welcome
@@umachadohow did you solve your problem again?
Hello together
I am trying to display a DTL format from the PLC into an I/O field. Unfortunately, I can't get it to work. How can this be solved?
I saw, that at Panel and Runtime work without Script. But at VoT is not working..
Hi,
I have a start & stop timestamp (DateTime format) but I want to display actual machine run hours that need to subtract from (start time - stop time).
So how to subtract the DateTime format?
Ex : (2022-02-17 12:45:41.960) - (2022-02-18 12:48:41.960) = 24.56
(Start Timestamp) - (Stop Timestamp) = Actual Run Hours
Hi,
I would split it. With this Math funtion you get the difference in milliseconds
let difference= Math.abs(day2-day1);
let Days = difference/(1000 * 3600 * 24)
let Hours = difference/(1000 * 3600 )
let Minutes= difference/(1000 * 60)
here you will find different solutions
stackoverflow.com/questions/3224834/get-difference-between-2-dates-in-javascript
Thank you for your help. Is this also working in V17. My textfield stays empty.
@@MyLittleHelper Hi, yes this should also work in V17, how does you script look?
@@DerHecht40
My Script is:
export function EA_Feld_1_ProcessValue_Trigger(item) {
let myDate = new Date();
let myLocalDate = myDate.toLocaleSting();
return myLocalDate;
}
But I've tried the exact same you did.
I think it has something to do with the trigger?
Trigger is T1S
@@MyLittleHelper please use toLocaleString(); you miss the "r" in your script
Works nice on PC webrowser. Browser in the HMI ignores date_time formats. Tried on MTP1200 Comfort Unified V18.
I did exactly as you explained, however I am using a button that sends the information to the TAG and this tab is displayed in an IO Field, however when I put the myLocal variable to write nothing happens
export function Button_1_OnTapped(item, x, y, modifiers, trigger) {
var value;
let myDate = new Date();
let myLocal = myDate.toLocaleTimeString();
value = myLocal;
HMIRuntime.Tags.SysFct.SetTagValue("dataInicio", value);
}
Hi,
the script looks correct, what datatype did you use?
Only WString is working, because you convert the time to an String
hello. Can you help me, how it's possible change time format from 12h to 24h in unified panel ?
Hi, via Java Script or where did you want to display it?
const date = new Date();
const hours = date.getHours(); // current hours in 24-hour format
const minutes = date.getMinutes();
let ampm = hours >= 12 ? 'PM' : 'AM'; // determine whether to use AM or PM
hours = hours % 12; // convert to 12-hour format
hours = hours ? hours : 12; // use 12 if hours is 0
const formattedTime = hours + ':' + minutes + ' ' + ampm; // time in 12-hour format
Hello i did the same but the time is not getting displayed its showing blank
This does not work the same when I try it. The value displayed for local date and time is incorrect. It's as if the toLocaleString() value is converted back to UTC by the IO Field control object.
Hi, do you use a output format on your I/O field? If yes, please remove it and try it again
Yes, I had the output format defined to display the time in the way I wanted. It does show the correct time without the formatting, which is very disappointing. The entire advantage of the IO field control vs textbox control in this case is the formatting.
@@andrewroy9369 Hi, how does the format looks you need?
@@DerHecht40 The output format makes it easy to produce a detailed display of date and time (e.g. October 30, 2020 11:59:59 PM). To produce that same format with JavaScript is a bit involved for what is supposed to be a short routine executed every second.
Hi There,
so the local date and time setting works so far as String. But i need the time and date seperatly in a I/O field. Do you know, how i can solve the requirement? things that i allready tried :1. I/O Field format into Date or Time 2. (tried) to changed the script (its tricky, without a console or syntax check it worked better befor with VBS and C). It's really anoying because you have to try it again and again and the reloading needs a lot of time... i also have a problem to read and write HMI Tags into I/O fields maybe it's possible to get a extra video oh them? i used the "snippets" but my I/O Fields are always filled with the start values. It doesn't make a difference to tap a button or not.
Okay i figured it out. If someone need :
var Value
let myDate = new Date();
let myLocal = myDate.toLocaleTimeString('de-DE');
Value = myLocal;
return(Value);
@@benjaminhaus8054 Hi, how did you manage to separate the date and time? i try to change on the output format but it wont work
@@hafizahmad3597 Hi, i habe to look, i can tell you how, tomorrow.
regards
@@benjaminhaus8054 It's ok, i already found it. To anyone who need it.
for time: let myLocal = myDate.toLocaleTimeString('de-DE');
for date: let myLocal = myDate.toLocaleDateString('de-DE');
@@hafizahmad3597 in my case i written :" var Value
let myDate = New Date();
Value = myDate;
return(Value);
And i formated the IO Field into {D,@dd.MM.yyyy}
have a nice day!
Hi friend, how do I show the system's digital clock (PLC)?
Hi, is it possible to set the clock of the panel in this way? ...not by control panel and not by ntp...
Hi,
I don#t know a solution to set the clock of the Panel from the Runtime
@@DerHecht40 OK, thx. Ich use now another solution. I use this ntp Server function from Siemens to set the Panel by PLC and i also send the timediference from Panel to PLC to set the localtime in PLC.
Thank you for the video!
Do you know how to visualize only the date?