# Conversion variable heure "hh:mm" en 2 variables numériques heure et minutes, et vice-versa

**URL:** <https://community.homey.app/t/conversion-variable-heure-hh-mm-en-2-variables-numeriques-heure-et-minutes-et-vice-versa/76756>\
**Category:** Questions & Aide\
**Created:** [February 22, 2023, 5:23pm UTC](https://community.homey.app/t/conversion-variable-heure-hh-mm-en-2-variables-numeriques-heure-et-minutes-et-vice-versa/76756 "2023-02-22T17:23:30Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Herve69](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/herve69/32/37183_2.png) [@Herve69](https://community.homey.app/u/Herve69)\
**Post date:** [February 22, 2023, 5:23pm UTC](https://community.homey.app/t/conversion-variable-heure-hh-mm-en-2-variables-numeriques-heure-et-minutes-et-vice-versa/76756/1 "2023-02-22T17:23:30Z")

</div>

Bonjour à tous,

Quelqu’un sait-il comment lire une chaine de caractères de type “hh:mm” (par exemple l’heure courante donnée par Homey) pour la convertir en deux nombres correspondant à l’heure et la minute, et inversement, comment obtenir une variable texte de type “hh:mm” à partir de deux nombres correspondant à l’heure et aux minutes ?

Pour info, je cherche cela pour faire des calculs sur l’heure idéale de démarrage de la filtration de ma piscine en fonction d’une part de la température de l’eau, et d’autre part de la période de la journée où mes panneaux solaires produisent le plus d’électricité. Exemple : La production max d’électricité des panneaux est à 11h30 chez moi. Si jamais le temps calculé pour la filtration est de 3h, alors je déclenche la filtration à 11h30 - 3h/2 = 10h, et je l’arrête à 11h30 + 3h/2 = 13h 🙂

J’espère que c’est tout clair ! Merci pour votre aide

---

<div class="post-metadata">

**Author:** ![Herve69](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/herve69/32/37183_2.png) [@Herve69](https://community.homey.app/u/Herve69)\
**Post date:** [February 23, 2023, 10:59am UTC](https://community.homey.app/t/conversion-variable-heure-hh-mm-en-2-variables-numeriques-heure-et-minutes-et-vice-versa/76756/2 "2023-02-23T10:59:28Z")

</div>

Pour ceux que ce sujet intéresse, je viens de poster la même question en anglais ici : [Conversion of time variable "hh:mm" into 2 numeric variables hour and minutes, and vice versa](https://community.homey.app/t/conversion-of-time-variable-hh-mm-into-2-numeric-variables-hour-and-minutes-and-vice-versa/76785) car il y a beaucoup plus d’anglophones que de francophones sur ce forum 🙂

---

<div class="post-metadata">

**Author:** ![sebyldino](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/sebyldino/32/20067_2.png) [@sebyldino](https://community.homey.app/u/sebyldino)\
**Post date:** [February 23, 2023, 4:06pm UTC](https://community.homey.app/t/conversion-variable-heure-hh-mm-en-2-variables-numeriques-heure-et-minutes-et-vice-versa/76756/3 "2023-02-23T16:06:04Z")

</div>

C’est possible avec Homeyscript.  
Tu peux récupérer l’heure et la séparer en 2 tags.  
Idem pour créer une heure.

---

<div class="post-metadata">

**Author:** ![Herve69](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/herve69/32/37183_2.png) [@Herve69](https://community.homey.app/u/Herve69)\
**Post date:** [February 23, 2023, 4:43pm UTC](https://community.homey.app/t/conversion-variable-heure-hh-mm-en-2-variables-numeriques-heure-et-minutes-et-vice-versa/76756/4 "2023-02-23T16:43:43Z")

</div>

C’est ce que j’ai cru comprendre en lisant d’autres posts, mais je ne pige pas comment rédiger les traitements avec BBL … 🤔 Si tu peux me donner la syntaxe, je suis preneur 🙏

Sinon pour info, le créateur de l’appli Action Scheduler m’a proposé une autre solution que je suis en train de tester cf [Conversion of time variable "hh:mm" into 2 numeric variables hour and minutes, and vice versa](https://community.homey.app/t/conversion-of-time-variable-hh-mm-into-2-numeric-variables-hour-and-minutes-and-vice-versa/76785)

---

<div class="post-metadata">

**Author:** ![sebyldino](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/sebyldino/32/20067_2.png) [@sebyldino](https://community.homey.app/u/sebyldino)\
**Post date:** [February 23, 2023, 7:43pm UTC](https://community.homey.app/t/conversion-variable-heure-hh-mm-en-2-variables-numeriques-heure-et-minutes-et-vice-versa/76756/5 "2023-02-23T19:43:35Z")

</div>

Pour créer un tag **numérique** heure et un tag **numérique** minute en fonction de l’heure actuelle:

```auto
let hours = new Date().getHours()+1; //+1 heure pour ajuster le fuseau horaire
let minutes = new Date().getMinutes();
await tag('heures', Number(hours)); 
await tag('minutes', Number(minutes));
return true;

```

Exemple pour déclencher ce script:

 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/f/f/ff4e45e78638f7c24afc1ca927716c368267d088.png)  
Où splitDate est le nom de ton script.

Pour créer un tag **string** d’heure au format hh:mm avec 2 variables:

```auto
let myArgs = JSON.parse(args[0]);
let createdTime = (myArgs.heures + ":" + myArgs.minutes);
await tag('created time', createdTime);
return true;

```

Exemple de flow pour récupérer ce tag:

 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/1/7/17a6d351e24202b07049acbc92020c8c72a363cb.png)

Comparer l’heure actuelle avec l’heure créée:

 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/3/7/37a0d29539bb5eaf6dd78c8e7c11968ac3e66b35.png)

---

<div class="post-metadata">

**Author:** ![Arie\_J\_Godschalk](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/arie_j_godschalk/32/63027_2.png) [@Arie\_J\_Godschalk](https://community.homey.app/u/Arie_J_Godschalk)\
**Post date:** [February 23, 2023, 10:05pm UTC](https://community.homey.app/t/conversion-variable-heure-hh-mm-en-2-variables-numeriques-heure-et-minutes-et-vice-versa/76756/6 "2023-02-23T22:05:12Z")

</div>

I am sorry, i do not speak or write French, so i’ll do this in English.

If i understand you correct, i think you might like the format card in the [Better Logic Library App](https://homey.app/nl-nl/app/net.i-dev.betterlogic/).

[[APP][Pro] Better Logic Library - For Users - Apps - Homey Community Forum](https://community.homey.app/t/app-pro-better-logic-library-for-users/71876/2)

it has a Format card which gives parts of the date exactly how you want it, based on your locale settings and timezone (configurable through the settings):

 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/2/e/2e85472773bf65613e69e150567c1c4e29b2ce06.png)  
(You can type anything you like it in and select the top one, which is what you typed).  
Now, this can be placed into variables directly:

 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/4/d/4d1be5a9b8b42c0102dfe390096f2033e3844748.png)

\*Set [variable] to BLL Expression cards  
Press execute to create the variables and tokens.

Now, to get this back to a HH:mm value, u can use this one: Execute Expression as Tag:  
 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/f/6/f6c585022a18391587f09cfa20cbbed823bb00d2.png)

```auto
"[Hour]".padStart(2,'0') + ':' + "[Minutes]".padStart(2,0)

```

\*Watch the double-quotes 😉

This will result in the time as usual:

 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/d/a/da5f6776beefa4023019d8e15b507328cdd49770.png)

N.b.  
Update to version 2.3.11 of BLL (in test now) to be able to create new variables through the expressionflowcard and resolve a bug where tags are not filled with a value at the first creation.

---

<div class="post-metadata">

**Author:** ![Herve69](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/herve69/32/37183_2.png) [@Herve69](https://community.homey.app/u/Herve69)\
**Post date:** [February 24, 2023, 9:38am UTC](https://community.homey.app/t/conversion-variable-heure-hh-mm-en-2-variables-numeriques-heure-et-minutes-et-vice-versa/76756/7 "2023-02-24T09:38:22Z")

</div>

@sebyldino : Merci, cette solution est très efficace … mais comme je ne suis vraiment pas à l’aise avec l’écriture de code, je préfère m’orienter vers les autres solutions proposées. Ainsi, je pourrai faire d’autres traitements similaires sans me demander à chaque fois comment rédiger le code correspondant ^^

@Arie_J_Godschalk : I guess it would be another solution, thanks. So I’ll try to do the flows and let you know.

Encore merci à tous !

---

<div class="post-metadata">

**Author:** ![Herve69](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/herve69/32/37183_2.png) [@Herve69](https://community.homey.app/u/Herve69)\
**Post date:** [February 24, 2023, 2:56pm UTC](https://community.homey.app/t/conversion-variable-heure-hh-mm-en-2-variables-numeriques-heure-et-minutes-et-vice-versa/76756/9 "2023-02-24T14:56:12Z")

</div>

Je partage le résultat fait avec l’appli Action Scheduler, que je conserve finalement car cela me semble être la solution la plus simple pour moi :

 ![flows](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/2/c/2ce21cbb4054acc87c95dc40d821ad440529d134.jpeg)

Encore merci à tous ceux qui m’ont aidé : @sebyldino , @Arie_J_Godschalk & @OH2TH 🙂

---

<div class="post-metadata">

**Author:** ![Rrrr](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/rrrr/32/629_2.png) [@Rrrr](https://community.homey.app/u/Rrrr)\
**Post date:** [April 3, 2023, 6:41am UTC](https://community.homey.app/t/conversion-variable-heure-hh-mm-en-2-variables-numeriques-heure-et-minutes-et-vice-versa/76756/10 "2023-04-03T06:41:23Z")

</div>

1. I’m using BLL to log the time when I send a notification.

Example: After midnight the formats H:mm:ss and HH:mm:ss result in 24:01:01

I see no option documented to get this to be 00:01:01 instead (which is I think the more regular way to display the time).

Is there a way?

1. I’m trying to set timezone to mountain time n the USA (salt lake city). It’s hard to search within the card. Where can I find more documentation?

2. Same for locale. I would like to understand better. Where can I find it?

---

<div class="post-metadata">

**Author:** ![Arie\_J\_Godschalk](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/arie_j_godschalk/32/63027_2.png) [@Arie\_J\_Godschalk](https://community.homey.app/u/Arie_J_Godschalk)\
**Post date:** [May 19, 2023, 9:42pm UTC](https://community.homey.app/t/conversion-variable-heure-hh-mm-en-2-variables-numeriques-heure-et-minutes-et-vice-versa/76756/11 "2023-05-19T21:42:40Z")

</div>

> [@Rrrr](#):
>
> I see no option documented to get this to be 00:01:01 instead (which is I think the more regular way to display the time).

This has been resolved in the latest BLL.

---

<div class="post-metadata">

**Author:** ![Rrrr](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/rrrr/32/629_2.png) [@Rrrr](https://community.homey.app/u/Rrrr)\
**Post date:** [May 20, 2023, 8:11am UTC](https://community.homey.app/t/conversion-variable-heure-hh-mm-en-2-variables-numeriques-heure-et-minutes-et-vice-versa/76756/12 "2023-05-20T08:11:57Z")

</div>

Working well, thank you.
