locked
I want to format time in HTML-Client RRS feed

  • Question

  • I have a lot of ftime fields in different tables. In Germany time is formated  in military format.

    The time is a number of Maximum 4 digits and is formated as follow.  130 Looks 01:30  1415 = 14:15 (2:15 pm)

    I wrote a Little Javascript to Format the number and this works fine.

    But I don't want to copy this in every postRender of every time in every Screen.

    Is there  possibility to do this with a Little custom control, or in worse case to attach the code below to a lot of times, without copy and pasting them.

    myapp.BrowseDisposaetze.ende_postRender = function (element, contentItem) {
            contentItem.dataBind("value", function (value) {
                if (value) {
                    var str = "000"+value;
                    str = str.substring(str.length-4);
                    str = str.substr(0, 2) + ":" + str.substr(2);
                    $(element).text(str);
                }
            });
        };

    Helmut


    Sunday, February 1, 2015 6:49 PM

Answers

  • Hello Helmut,

    a custom control I'm not Aware of. I have the same ask for colouring values and I use a custom function.

    Make a new js-Script (maybe: GlobalFunction.js) file and put this into your Scripts Folder. Add this file to your Default.htm where the other js File live.

    In your file GlobalFUnction.js add

    function ConvertMilitaryTime(p1)

    {

                    var str = "000"+p1;
                    str
    = str.substring(str.length-4);
                    str
    = str.substr(0, 2) + ":" + str.substr(2);
                   return str;
    }

    In your HTML Client Function call your new Function

    contentItem.dataBind("value", function (value) {

    $(element).text = ConvertMilitaryTime(value);

    }Hope this helps
    Kind Regards

    Thomas

    • Marked as answer by Helmut Seitz Monday, February 2, 2015 9:54 AM
    Monday, February 2, 2015 8:10 AM

All replies

  • Hello Helmut,

    a custom control I'm not Aware of. I have the same ask for colouring values and I use a custom function.

    Make a new js-Script (maybe: GlobalFunction.js) file and put this into your Scripts Folder. Add this file to your Default.htm where the other js File live.

    In your file GlobalFUnction.js add

    function ConvertMilitaryTime(p1)

    {

                    var str = "000"+p1;
                    str
    = str.substring(str.length-4);
                    str
    = str.substr(0, 2) + ":" + str.substr(2);
                   return str;
    }

    In your HTML Client Function call your new Function

    contentItem.dataBind("value", function (value) {

    $(element).text = ConvertMilitaryTime(value);

    }Hope this helps
    Kind Regards

    Thomas

    • Marked as answer by Helmut Seitz Monday, February 2, 2015 9:54 AM
    Monday, February 2, 2015 8:10 AM
  • Thomas,

    thank you for the quick answer.

    I think a global js is a good idea.

    Helmut

    Monday, February 2, 2015 9:54 AM
  • Perhaps try moment.js http://momentjs.com/

    Monday, February 2, 2015 8:55 PM