I have a Following line of code. The Date of string type is in the format 29/11/2017.
I wanted it as November 29, 2017.
I tried adding String.Format but it display the same 29/11/2017 in pdf.
cellValDate.AddElement(new Phrase(String.Format("{0:dddd, MMMM d, yyyy}",
txtDate.Text, CultureInfo.CreateSpecificCulture("en-US")),
new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA,
10, iTextSharp.text.Font.NORMAL)));
First you need to parse and convert the date string value in txtDate.Text to a DateTime object.
DateTime dt = DateTime.ParseExact(txtDate.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture);
Then convert it to the particular format- "Month Day, Year".
string formateDate = dt.ToString("MMMM dd, yyyy");
Then you can pass it to your code-
cellValDate.AddElement(new Phrase(formateDate,
new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA,
10, iTextSharp.text.Font.NORMAL)));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With