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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T03:50:47+00:00 2026-05-11T03:50:47+00:00

I’m to get a custom DateTime format including the AM/PM designator, but I want

  • 0

I’m to get a custom DateTime format including the AM/PM designator, but I want the ‘AM’ or ‘PM’ to be lowercase without making the rest of of the characters lowercase.

Is this possible using a single format and without using a regex?

Here’s what I’ve got right now:

item.PostedOn.ToString('dddd, MMMM d, yyyy a\\t h:mmtt') 

An example of the output right now would be Saturday, January 31, 2009 at 1:34PM

  • 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. 2026-05-11T03:50:47+00:00Added an answer on May 11, 2026 at 3:50 am

    I would personally format it in two parts: the non-am/pm part, and the am/pm part with ToLower:

    string formatted = item.PostedOn.ToString('dddd, MMMM d, yyyy a\\t h:mm') +                    item.PostedOn.ToString('tt').ToLower(); 

    Another option (which I’ll investigate in a sec) is to grab the current DateTimeFormatInfo, create a copy, and set the am/pm designators to the lower case version. Then use that format info for the normal formatting. You’d want to cache the DateTimeFormatInfo, obviously…

    EDIT: Despite my comment, I’ve written the caching bit anyway. It probably won’t be faster than the code above (as it involves a lock and a dictionary lookup) but it does make the calling code simpler:

    string formatted = item.PostedOn.ToString('dddd, MMMM d, yyyy a\\t h:mmtt',                                           GetLowerCaseInfo()); 

    Here’s a complete program to demonstrate:

    using System; using System.Collections.Generic; using System.Globalization;  public class Test {     static void Main()     {         Console.WriteLine(DateTime.Now.ToString('dddd, MMMM d, yyyy a\\t h:mmtt',                                                 GetLowerCaseInfo());     }      private static readonly Dictionary<DateTimeFormatInfo,DateTimeFormatInfo> cache =         new Dictionary<DateTimeFormatInfo,DateTimeFormatInfo>();      private static object cacheLock = new object();      public static DateTimeFormatInfo GetLowerCaseInfo()     {         DateTimeFormatInfo current = CultureInfo.CurrentCulture.DateTimeFormat;         lock (cacheLock)         {             DateTimeFormatInfo ret;             if (!cache.TryGetValue(current, out ret))             {                 ret = (DateTimeFormatInfo) current.Clone();                 ret.AMDesignator = ret.AMDesignator.ToLower();                 ret.PMDesignator = ret.PMDesignator.ToLower();                 cache[current] = ret;             }             return ret;         }     } } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
I need to clean up various Word 'smart' characters in user input, including but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I want to construct a data frame in an Rcpp function, but when I
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported

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.