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?
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?
using Date object same you can create time format also.
To create filename format use javascript replaceenter link description here method
Check this to create trim method or extend javascript String Object
Hope this is enough to convert your server side code in java script…