1

I would like to display my timestamp in the front as the date. I tried several methods but none worked. here is the code:`

formulaire.addEventListener('submit', posteValidation);
/**
 *  Fonction pour ajouter une publication dans le serveur
 * @param {Event} event 
 */
const addPosteServeur = async (event) => {
    event.preventDefault();
    if(formulaire.checkValidity()){
        let data = {
            id_user: 1,
            timestamps: date.getTime(),
            text : textPoste.value
        }
        let response = await fetch('/', {
            method: 'POST',
            headers: {'Content-Type': 'application/json'},
            body: JSON.stringify(data)
        });
        if(response.ok){
            addPosteClient({
                id_user: 1,
                timestamps: date.getTime(),
                text: textPoste.value
            });

            textPoste.value = '';
        }
    }
}
formulaire.addEventListener('submit', addPosteServeur);`

Thanks

3
  • what exactly do you want to show? what value does date in your code have? Commented Jun 1, 2022 at 20:56
  • How is this code relevant to your question? We need to see the addPosteClient function and how it displays the timestamp. And what do node.js or express have to do with any of this? Commented Jun 1, 2022 at 21:05
  • Currently it is a sequence of timestamp numbers. I want to convert it to date in addPosteClient() Commented Jun 1, 2022 at 21:33

1 Answer 1

1

to get the date as timestamp in Node.js simply do Date.now(). If you want to get the date as string, you can use new Date().toUTCString() I suggest you to read the Date API that can be found here https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.