# Convert Seconds to date format

**URL:** <https://forum.genieacs.com/t/convert-seconds-to-date-format/856>\
**Category:** Uncategorized\
**Created:** [June 24, 2020, 3:15pm UTC](https://forum.genieacs.com/t/convert-seconds-to-date-format/856 "2020-06-24T15:15:29Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![dev\_boi](https://avatars.discourse-cdn.com/v4/letter/d/3d9bf3/32.png) [@dev\_boi](https://forum.genieacs.com/u/dev_boi)\
**Post date:** [June 24, 2020, 3:15pm UTC](https://forum.genieacs.com/t/convert-seconds-to-date-format/856/1 "2020-06-24T15:15:29Z")

</div>

Hello everyone, I have a request for you :

I have a value, exemple value = 60000, which is the uptime in second of a device. This value is a child parameter.  
I want to view this value into a regular date format (HH:MM:SS).  
I want to know if you have fonctions or methods to do it.

And can you tell me if all the display config is in YAML please.

Thank you in advance for your replies.

---

<div class="post-metadata">

**Author:** ![akcoder](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.genieacs.com/akcoder/32/11_2.png) [@akcoder](https://forum.genieacs.com/u/akcoder)\
**Post date:** [June 24, 2020, 3:31pm UTC](https://forum.genieacs.com/t/convert-seconds-to-date-format/856/2 "2020-06-24T15:31:11Z")

</div>

You don’t mention what version of GenieACS you are using. In v1.0 and v1.1 (not sure about v1.2 as we haven’t migrated yet) there is support. In v1.0 and v1.1 look in the `gui/config/parameter_renders.yml` file. You will see a mapping between parameters and parameter renderers. You can even write your own by in ruby storing them in `gui/config/parameter_renderers`.

Example from my environment:

```auto
InternetGatewayDevice.DeviceInfo.UpTime: duration
Device.DeviceInfo.UpTime: duration
VirtualParameters.UpTime: duration
VirtualParameters.pppoeUsername: username_link
_deviceId._SerialNumber: serial_number_link
_tags: tags
_lastBoot: date_local

```

The two renderers `username_link` and `serial_number_link` are custom ones I’ve written.

---

<div class="post-metadata">

**Author:** ![dev\_boi](https://avatars.discourse-cdn.com/v4/letter/d/3d9bf3/32.png) [@dev\_boi](https://forum.genieacs.com/u/dev_boi)\
**Post date:** [June 25, 2020, 7:31am UTC](https://forum.genieacs.com/t/convert-seconds-to-date-format/856/3 "2020-06-25T07:31:21Z")

</div>

Thanks for your reply.

I use the last version : the 1.2 beta, so do you know if this version keeps the files you mentioned ?

---

<div class="post-metadata">

**Author:** ![zaidka](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.genieacs.com/zaidka/32/9_2.png) [@zaidka](https://forum.genieacs.com/u/zaidka)\
**Post date:** [June 25, 2020, 10:01am UTC](https://forum.genieacs.com/t/convert-seconds-to-date-format/856/4 "2020-06-25T10:01:35Z")

</div>

There’s the function `DATE_STRING()` but that renders a datetime, not a duration. Maybe create a custom component to render a numeric parameter in that format? See `ui/components/parameter.ts` for an example component.

---

<div class="post-metadata">

**Author:** ![KGcasa](https://avatars.discourse-cdn.com/v4/letter/k/f4b2a3/32.png) [@KGcasa](https://forum.genieacs.com/u/KGcasa)\
**Post date:** [June 30, 2020, 4:24pm UTC](https://forum.genieacs.com/t/convert-seconds-to-date-format/856/5 "2020-06-30T16:24:37Z")

</div>

I do this via a virtual parameter. For example I convert UpTime to a format DDd hh:mm:ss with a Virtual Parameter called UpTimeDHMS.

There may be more efficient ways to write the code, my aim is for simplicity and clarity.

```
// Unified across Device and InternetGatewayDevice
let v1 = declare("Device.DeviceInfo.UpTime", {value: Date.now()});
let v2 = declare("InternetGatewayDevice.DeviceInfo.UpTime", {value: Date.now()});
let totalSecs = 0
if (typeof v1.value !== "undefined") {
  totalSecs = v1.value[0];
} else {
  totalSecs = v2.value[0];
}
let days = Math.floor(totalSecs / 86400);
let rem = totalSecs % 86400;
let hrs = Math.floor(rem / 3600);
if (hrs < 10) {
	hrs = "0" + hrs;
}

rem = rem % 3600;
let mins = Math.floor(rem / 60);
if (mins < 10) {
	mins = "0" + mins;
}
let secs = rem % 60;
if (secs < 10) {
	secs = "0" + secs;
}

let uptime = days + "d " + hrs + ":" + mins + ":" + secs;
return {writable: false, value: uptime};

```

This is how it renders:

 ![DHMS_render_example](https://canada1.discourse-cdn.com/flex035/uploads/genieacs/original/1X/504ced00d6009bfe2c8e2b4028ccc230b315572e.png)

---

<div class="post-metadata">

**Author:** ![dev\_boi](https://avatars.discourse-cdn.com/v4/letter/d/3d9bf3/32.png) [@dev\_boi](https://forum.genieacs.com/u/dev_boi)\
**Post date:** [July 2, 2020, 5:35pm UTC](https://forum.genieacs.com/t/convert-seconds-to-date-format/856/6 "2020-07-02T17:35:35Z")

</div>

Hello,

Thank you for your reply and your solution. This is exactly what I am looking for ^^

---

<div class="post-metadata">

**Author:** ![jriera](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.genieacs.com/jriera/32/395_2.png) [@jriera](https://forum.genieacs.com/u/jriera)\
**Post date:** [January 19, 2021, 11:10pm UTC](https://forum.genieacs.com/t/convert-seconds-to-date-format/856/7 "2021-01-19T23:10:13Z")

</div>

So the ideal would be to include this in the genie code at “parameter.ts”:

```
if (e[0] === "FUNC" && e[1] === "DATE_STRING" && !Array.isArray(e[2])) {
  return new Date(e[2]).toLocaleString();
}
else if (e[0] === "FUNC" && e[1] === "SECONDS" && !Array.isArray(e[2])) {
    let totalSecs = e[2];
    let days = Math.floor(totalSecs / 86400);
    let rem = totalSecs % 86400;
    let hrs = Math.floor(rem / 3600);
    if (hrs < 10) {
            hrs = "0" + hrs;
    }

    rem = rem % 3600;
    let mins = Math.floor(rem / 60);
    if (mins < 10) {
            mins = "0" + mins;
    }
    let secs = rem % 60;
    if (secs < 10) {
            secs = "0" + secs;
    }
    return days + "d " + hrs + ":" + mins + ":" + secs;
}
return e;

```

});

---

<div class="post-metadata">

**Author:** ![mtarifa](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.genieacs.com/mtarifa/32/848_2.png) [@mtarifa](https://forum.genieacs.com/u/mtarifa)\
**Post date:** [January 24, 2021, 2:19pm UTC](https://forum.genieacs.com/t/convert-seconds-to-date-format/856/8 "2021-01-24T14:19:10Z")

</div>

hello, yes it will be good as jriera say. i was try to get the connection time from some wifi stations.  
I tryed to add that on parameter.ts but it complain during the run build. I revert back the file since i dont have a programming skills (also for create a external function or sort of):

/usr/src/genieacs# npm run build

> genieacs@1.2.3 build /usr/src/genieacs  
> node -r esm -r ts-node/register/transpile-only build/build

@rollup/plugin-typescript TS2322: Type ‘string’ is not assignable to type ‘number’.  
@rollup/plugin-typescript TS2322: Type ‘string’ is not assignable to type ‘number’.  
@rollup/plugin-typescript TS2322: Type ‘string’ is not assignable to type ‘number’.

regards

---

<div class="post-metadata">

**Author:** ![bangdrie](https://avatars.discourse-cdn.com/v4/letter/b/8baadc/32.png) [@bangdrie](https://forum.genieacs.com/u/bangdrie)\
**Post date:** [December 21, 2022, 4:42am UTC](https://forum.genieacs.com/t/convert-seconds-to-date-format/856/9 "2022-12-21T04:42:44Z")

</div>

hii, how to configure like this ? can you explain me ? thanks

---

<div class="post-metadata">

**Author:** ![aanyoti](https://avatars.discourse-cdn.com/v4/letter/a/ba8739/32.png) [@aanyoti](https://forum.genieacs.com/u/aanyoti)\
**Post date:** [November 13, 2023, 3:51am UTC](https://forum.genieacs.com/t/convert-seconds-to-date-format/856/10 "2023-11-13T03:51:46Z")

</div>

Thank you for this extremely helpful post @KGcasa
