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 7791303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:50:41+00:00 2026-06-01T21:50:41+00:00

Colls, I have a code which should create a sToday variable which returns timestamp

  • 0

Colls, I have a code which should create a sToday variable which returns timestamp like “DD_MM_YYYY_HH_MI_SS”:

var today = new Date();

var CurrentDay = today.getDay();
var CurrentMonth = today.getMonth();
var CurrentHours = today.getHours();
var CurrentMin = today.getMinutes();
var CurrentSec = today.getSeconds();

if (CurrentDay < 10)
   sToday = "0"+today.getDay().toString();
else 
   sToday = today.getDay().toString();

if(CurrentMonth<10)
  sToday += "_0"+today.getMonth().toString();
else 
  sToday += "_"+today.getMonth().toString();

sToday += "_"+today.getYear().toString();

if (CurrentHours<10)
  sToday += "_0"+today.getHours().toString();
else 
  sToday += "_"+today.getHours().toString();

if (CurrentMin<10)  
  sToday += "_0"+today.getMinutes().toString();
else 
  sToday += "_"+today.getMinutes().toString();

if (CurrentSec<10)
sToday += "_0"+today.getSeconds().toString();
else
sToday += "_"+today.getSeconds().toString();

But when I run it 13.04.2012 20:20:14 (my pc time) then I receive 05_03_2012_20_20_14 .
How to fix this and receive 13_04_2012_20_20_14 ?

  • 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-01T21:50:43+00:00Added an answer on June 1, 2026 at 9:50 pm

    getDate returns the date 1-31. getDay returns the day of the week 0-6, with 0 being Sunday.
    getMonth returns the month 0-11, so you need to add 1 to that value.

    Instead of printing Date, Month, right now, you’re printing Day, Month – 1.

    Alter your code to this:

    if (CurrentDay < 10)
       sToday = "0"+today.getDate().toString();
    else 
       sToday = today.getDate().toString();
    
    if(CurrentMonth<10)
      sToday += "_0"+ (today.getMonth() + 1).toString();
    else 
      sToday += "_"+(today.getMonth() + 1).toString();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have code like that: var xPola = 10, //how many cols yPola =
I have this code: s(x => x.Open()); s is a method which calls one
I am using the new libcxx library and I have a code that calls
i have a tableview which has image and a text behind, i create the
I have a datatable being built in code which can dynamically have any given
I have code which uses the StreamReader to read HTML from a file, then
I am new to WCF,my task is to create,maintain sessions in WCF I have
I am asked to develop a software which should be able to create Flow
I have a program complete with a number of classes which create complex objects,
Currently I have code like the following (simplified somewhat). Eventually, I've added more and

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.