0

I am doing something to prepare a string to display in a format in server side but now I have to replace it in javascript so my server side code is:

 DateTime now = DateTime.Now;
            string date = now.GetDateTimeFormats('d')[0];
            string time = now.GetDateTimeFormats('t')[0];

                txtFileName.Value = someString.Length > 10 ? someString.Substring(0, 10).TrimEnd() + "_" + date + "_" + time : someString.TrimEnd() + "_" + date + "_" + time;
            txtFileName.Value = txtFileName.Value.Replace(' ', '_');

How to achieve that?

Cœur
  • 34,719
  • 24
  • 185
  • 251
ankur
  • 4,224
  • 14
  • 59
  • 96

2 Answers2

0

check out DateJS, it has very powerfull date manipulation functions

epoch
  • 16,149
  • 3
  • 42
  • 69
0

Although JavaScript provides a bunch of methods for getting and setting parts of a date object, it lacks a simple way to format dates and times according to a user-specified mask.

Check these date function and follow following links:
Formatting a date in javascript
How can I convert string to datetime with format specification in JavaScript?

var d = new Date();
var datepart = d.getDate() + "  " + d.getMonth() + " " + d.getFullYear();

using Date object same you can create time format also.

To create filename format use javascript replaceenter link description here method

var myNewString = myOldString.replace("username", visitorName);

Check this to create trim method or extend javascript String Object

Hope this is enough to convert your server side code in java script...

Community
  • 1
  • 1
Niranjan Singh
  • 17,741
  • 2
  • 40
  • 74