Set Date Time format in column

Posted by: ricardo.salas on 18 October 2017, 6:23 pm EST

    • Post Options:
    • Link

    Posted 18 October 2017, 6:23 pm EST

    I want to set a column’s format to a DateTime, so it shows data in this format (or similar):

    02/11/2016 02:35:56 A.M.

    Is it possible to do this without a custom cell type? And also make sure that the sorting works as expected?

    Thanks

  • Posted 23 October 2017, 7:29 am EST

    Hello,

    You can use below mentioned format for the same:-

        <script type="text/javascript">
            $(document).ready(function () {
                var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"), { sheetCount: 1 });
                var activeSheet = spread.getSheet(0);
    
                activeSheet.getCell(0, 1).formatter(new GC.Spread.Formatter.GeneralFormatter("dd/MM/yyyy hh:mm:ss tt", "en-us"));
                activeSheet.setValue(0, 1, 	new Date($.now()), GC.Spread.Sheets.SheetArea.viewport);
    
            });
        </script>
    

    Hope it helps.

    Thanks,

    Reeva

  • Posted 24 October 2017, 4:03 pm EST

    I wanted to do something at column level and not cell by cell, is that possible?

    I tried that method, but the call to GeneralFormatter ended up looking like this to make it work:

    vm.sheet.getCell(i, 6).formatter(new GC.Spread.Formatter.GeneralFormatter('MM/DD/YYYY hh:mm:ss AM/PM', 0));
    

    I couldn’t find that ‘AM/PM’ anywhere in the documentation, also see that the second parameter is different. I was lucky to find an example inside the SpreadJS code

  • Posted 26 October 2017, 10:53 am EST

    Hello,

    You can simply use the code as follows to do it for whole column:3

    vm.sheet.getCell(-1, 6).formatter(new GC.Spread.Formatter.GeneralFormatter(‘MM/DD/YYYY hh:mm:ss AM/PM’, 0));

    Thanks,

    Deepak Sharma

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels