Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I remove the seconds from a date/time string in either JavaScript or c#?

Tags:

javascript

c#

I have the option of using either JavaScript or c# to accomplish this task.

I have a lot of strings in the format "10/14/2012 8:45:34 PM" How do I remove the seconds and retain the PM like so "10/14/2012 8:45PM"?

I can't use substring because the length of the string will be different with each day and time.

like image 693
Ben Avatar asked Jul 16 '26 01:07

Ben


1 Answers

In C#, you can do this:

myTime.ToString("MM/dd/yyyy hh:mmtt");

Alternatively, you can use the built in Format Specifiers described here.

Edit - I removed the space between mm and tt because I just noticed your post shows 8:45PM. You can add a space between mm and tt if you want it to be 8:45 PM.

like image 134
keyboardP Avatar answered Jul 17 '26 14:07

keyboardP



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!