Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8789723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:29:26+00:00 2026-06-13T22:29:26+00:00

Using NodeJS, I want to format a Date into the following string format: var

  • 0

Using NodeJS, I want to format a Date into the following string format:

var ts_hms = new Date(UTC);
ts_hms.format("%Y-%m-%d %H:%M:%S");

How do I do that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T22:29:29+00:00Added an answer on June 13, 2026 at 10:29 pm

    If you’re using Node.js, you’re sure to have EcmaScript 5, and so Date has a toISOString method. You’re asking for a slight modification of ISO8601:

    new Date().toISOString()
    > '2012-11-04T14:51:06.157Z'
    

    So just cut a few things out, and you’re set:

    new Date().toISOString().
      replace(/T/, ' ').      // replace T with a space
      replace(/\..+/, '')     // delete the dot and everything after
    > '2012-11-04 14:55:45'
    

    Or, in one line: new Date().toISOString().replace(/T/, ' ').replace(/\..+/, '')

    ISO8601 is necessarily UTC (also indicated by the trailing Z on the first result), so you get UTC by default (always a good thing).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following string gets encoded in my source XML using toggles, and I want
Am developing one using nodejs scraping and mysql. I want to store details into
I'm using the JavaScript mongodb driver from nodejs. I want to do this query
I'm using Nodejs and Socket.io. When the client connects, new JavaScript objects are created.
I've have a web site I'm building using NodeJS, that needs to serve up
Maybe it's just the fact that I've been using http://nodejs.org/ lately, but the lack
I have a xml document on the following format and want to transform it
I want to realize a simple client-server connection using Nodejs. But I've encountered with
I'm using nodejs and nowjs. I want to get the body length of the
I'm using NodeJs and native MongoDB driver for creating an application. I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.