WinCC Unified V16: Digital clock with JavaScript

Поділитися
Вставка
  • Опубліковано 27 гру 2024

КОМЕНТАРІ • 42

  • @mehdiaidel4547
    @mehdiaidel4547 2 роки тому +2

    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
      @umachado Рік тому +1

      I'm having the same problema. The problem started after updating the OS to version 5.

    • @mehdiaidel4547
      @mehdiaidel4547 Рік тому

      @@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)

    • @umachado
      @umachado Рік тому +1

      @@mehdiaidel4547 Thank you for the help. I tried to remove the format of the field an then it worked.

    • @mehdiaidel4547
      @mehdiaidel4547 Рік тому

      @@umachado great !
      You are welcome

    • @Time4yes
      @Time4yes 4 місяці тому

      ​@@umachadohow did you solve your problem again?

  • @ernestolienhard
    @ernestolienhard Рік тому

    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?

    • @ernestolienhard
      @ernestolienhard Рік тому

      I saw, that at Panel and Runtime work without Script. But at VoT is not working..

  • @nirubanchakkaravarthi952
    @nirubanchakkaravarthi952 2 роки тому

    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

    • @DerHecht40
      @DerHecht40  2 роки тому +2

      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

    • @MyLittleHelper
      @MyLittleHelper 2 роки тому

      Thank you for your help. Is this also working in V17. My textfield stays empty.

    • @DerHecht40
      @DerHecht40  2 роки тому

      @@MyLittleHelper Hi, yes this should also work in V17, how does you script look?

    • @MyLittleHelper
      @MyLittleHelper 2 роки тому

      @@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

    • @DerHecht40
      @DerHecht40  2 роки тому +1

      @@MyLittleHelper please use toLocaleString(); you miss the "r" in your script

  • @miroslavandroid9638
    @miroslavandroid9638 11 місяців тому

    Works nice on PC webrowser. Browser in the HMI ignores date_time formats. Tried on MTP1200 Comfort Unified V18.

  • @lucaspinheiro2624
    @lucaspinheiro2624 Рік тому

    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);
    }

    • @DerHecht40
      @DerHecht40  Рік тому

      Hi,
      the script looks correct, what datatype did you use?
      Only WString is working, because you convert the time to an String

  • @samponelam
    @samponelam Рік тому

    hello. Can you help me, how it's possible change time format from 12h to 24h in unified panel ?

    • @DerHecht40
      @DerHecht40  Рік тому

      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

  • @raghulkumar9343
    @raghulkumar9343 Рік тому

    Hello i did the same but the time is not getting displayed its showing blank

  • @andrewroy9369
    @andrewroy9369 4 роки тому

    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.

    • @DerHecht40
      @DerHecht40  4 роки тому

      Hi, do you use a output format on your I/O field? If yes, please remove it and try it again

    • @andrewroy9369
      @andrewroy9369 4 роки тому

      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
      @DerHecht40  4 роки тому

      @@andrewroy9369 Hi, how does the format looks you need?

    • @andrewroy9369
      @andrewroy9369 4 роки тому

      @@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.

  • @benjaminhaus8054
    @benjaminhaus8054 2 роки тому

    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.

    • @benjaminhaus8054
      @benjaminhaus8054 2 роки тому +1

      Okay i figured it out. If someone need :
      var Value
      let myDate = new Date();
      let myLocal = myDate.toLocaleTimeString('de-DE');
      Value = myLocal;
      return(Value);

    • @hafizahmad3597
      @hafizahmad3597 2 роки тому

      @@benjaminhaus8054 Hi, how did you manage to separate the date and time? i try to change on the output format but it wont work

    • @benjaminhaus8054
      @benjaminhaus8054 2 роки тому

      @@hafizahmad3597 Hi, i habe to look, i can tell you how, tomorrow.
      regards

    • @hafizahmad3597
      @hafizahmad3597 2 роки тому +1

      @@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');

    • @benjaminhaus8054
      @benjaminhaus8054 2 роки тому +1

      @@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!

  • @erikflores6585
    @erikflores6585 2 роки тому

    Hi friend, how do I show the system's digital clock (PLC)?

  • @TheDodi1980
    @TheDodi1980 2 роки тому

    Hi, is it possible to set the clock of the panel in this way? ...not by control panel and not by ntp...

    • @DerHecht40
      @DerHecht40  2 роки тому

      Hi,
      I don#t know a solution to set the clock of the Panel from the Runtime

    • @TheDodi1980
      @TheDodi1980 2 роки тому

      @@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.

  • @diegomeli9008
    @diegomeli9008 9 місяців тому

    Thank you for the video!
    Do you know how to visualize only the date?