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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:53:14+00:00 2026-06-13T12:53:14+00:00

I generate a PDF from html source code. I read all the text line

  • 0

I generate a PDF from html source code. I read all the text line by line. I need to get all the dates from whole document. I do get all the dates using regular expression. The problem is i need to convert the string which can be in any date format(dd-MM-yyyy or yyyy-mm-dd or dd/mm/yyyy) to a specific date format (dd MMMM yyyy). I am stuck with this. Any help will be great. I need to read the date format string contains. here is my code…

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fileDocumentDirectorySavePath = [documentsDirectory stringByAppendingPathComponent:@"Sample.txt"];

NSFileManager *fm = [NSFileManager defaultManager];
if (![fm fileExistsAtPath:fileDocumentDirectorySavePath])
    [fm copyItemAtPath:fileBundlePath toPath:fileDocumentDirectorySavePath error:nil];

NSString* fileContents = 
[NSString stringWithContentsOfFile:fileDocumentDirectorySavePath 
                          encoding:NSUTF8StringEncoding error:nil];

// first, separate by new line
NSArray* allLinedStrings = 
[fileContents componentsSeparatedByCharactersInSet:
 [NSCharacterSet newlineCharacterSet]];
NSString* strsInOneLine;
NSArray *DateArray;
// NSString * regularExpression = @"([1-9]|0[1-9]|[12][0-9]|3[01])(st|nd|rd|th) \\w* (19|20)\\d\\d |(\\d{2}-\\d{2}-\\d{4})|(\\d{4}-\\d{2}-\\d{2})|(\\d{2}/\\d{2}/\\d{4})|(\\d{4}/\\d{2}/\\d{2})";

NSString * regularExpression = @"([1-9]|0[1-9]|[12][0-9]|3[01])(st|nd|rd|th) \\w* (19|20)\\d\\d |(\\d{2}-\\d{2}-\\d{4})|(\\d{4}-\\d{2}-\\d{2})|(\\d{2}/\\d{2}/\\d{4})|(\\d{4}/\\d{2}/\\d{2})|((31(?!\\ (Feb(ruary)?|Apr(il)?|June?|(Sep(?=\\b|t)t?|Nov)(ember)?)))|((30|29)(?!\\ Feb(ruary)?))|(29(?=\\Feb(ruary)?\\ (((1[6-9]|[2-9]\\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)))))|(0?[1-9])|1\\d|2[0-8])\\ (Jan(uary)?|Feb(ruary)?|Ma(r(ch)?|y)|Apr(il)?|Ju((ly?)|(ne?))|Aug(ust)?|Oct(ober)?|(Sep(?=\\b|t)t?|Nov|Dec)(ember)?)\\ ((1[6-9]|[2-9]\\d)\\d{2})";
NSError *error = NULL;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:regularExpression
                                                                       options:NSRegularExpressionCaseInsensitive
                                                                         error:&error];
NSString *resultString;

for (int i = 0; i < [allLinedStrings count]; i++) {
           strsInOneLine = [allLinedStrings objectAtIndex:i];
    DateArray = [regex matchesInString:strsInOneLine options:0 range:NSMakeRange(0, [strsInOneLine length])];
    for (NSTextCheckingResult* result in DateArray)
    {
        resultString = [strsInOneLine substringWithRange:result.range];
        NSLog(@"RESULT STRING ===== >%@",resultString);

        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
        [dateFormatter setDateFormat:@"dd-MM-yyyy"];
        NSDate *yourDate = [dateFormatter dateFromString:resultString];
        NSLog(@"NEW DATE ====== > %@",yourDate);
        NSString *myDateStr;
        [dateFormatter setDateFormat:@"dd MMMM yyyy"];
        myDateStr = [dateFormatter stringFromDate:yourDate];
        NSLog(@"NEW DATE STRING ====== > %@",myDateStr);


    }

}
  • 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. Editorial Team
    Editorial Team
    2026-06-13T12:53:15+00:00Added an answer on June 13, 2026 at 12:53 pm

    There are no direct way to get this. However there is a work around like this which will work in most of the cases. All you have to do is to add all the possible date formatter to the below dateFormatterList.

    - (NSString *)dateStringFromString:(NSString *)sourceString destinationFormat:(NSString *)destinationFormat {
    
        NSString *convertedDateString = nil;
        NSArray *dateFormatterList = [NSArray arrayWithObjects:@"yyyy-MM-dd'T'HH:mm:ss'Z'", @"yyyy-MM-dd'T'HH:mm:ssZ",
                                      @"yyyy-MM-dd'T'HH:mm:ss", @"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'",
                                      @"yyyy-MM-dd'T'HH:mm:ss.SSSZ", @"yyyy-MM-dd HH:mm:ss",
                                      @"MM/dd/yyyy HH:mm:ss", @"MM/dd/yyyy'T'HH:mm:ss.SSS'Z'",
                                      @"MM/dd/yyyy'T'HH:mm:ss.SSSZ", @"MM/dd/yyyy'T'HH:mm:ss.SSS",
                                      @"MM/dd/yyyy'T'HH:mm:ssZ", @"MM/dd/yyyy'T'HH:mm:ss",
                                      @"yyyy:MM:dd HH:mm:ss", @"yyyyMMdd", @"dd-MM-yyyy",
                                      @"dd/MM/yyyy", @"yyyy-MM-dd", @"yyyy/MM/dd",
                                      @"dd MMMM yyyy", @"MMddyyyy", @"MM/dd/yyyy",
                                      @"MM-dd-yyyy", @"d'st' MMMM yyyy",
                                      @"d'nd' MMMM yyyy", @"d'rd' MMMM yyyy",
                                      @"d'th' MMMM yyyy", @"d'st' MMM yyyy",
                                      @"d'nd' MMM yyyy", @"d'rd' MMM yyyy",
                                      @"d'th' MMM yyyy", @"d'st' MMMM",
                                      @"d'nd' MMMM", @"d'rd' MMMM",
                                      @"d'th' MMMM", @"d'st' MMM",
                                      @"d'nd' MMM", @"d'rd' MMM",
                                      @"d'th' MMM", @"MMMM, yyyy",
                                      @"MMMM yyyy", nil];
    
        //sourceString = @"20/11/2012";
        //destinationFormat  = @"dd MMMM yyyy";
    
        if (sourceString) {
    
            NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    
            for (NSString *dateFormatterString in dateFormatterList) {
    
                [dateFormatter setDateFormat:dateFormatterString];
                NSDate *originalDate = [dateFormatter dateFromString:sourceString];
    
                if (originalDate) {
    
                    [dateFormatter setDateFormat:destinationFormat];
                    convertedDateString = [dateFormatter stringFromDate:originalDate];
                    NSLog(@"Converted date String is %@", convertedDateString);
                    break;
                }
            }
            [dateFormatter release];
        }
    
        return convertedDateString;
    }
    

    Add this to your class and use it as,

    NSLog(@"%@", [self dateStringFromString:@"2nd August 2012" destinationFormat:@"dd-MM-yyyy"]);
    

    Output: 02-08-2012

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to automatically generate a PDF file from an exisiting (X)HTML-document. The input
I have document source in XML. I need to generate PDF and HTML pages
I need a code snippet to generate a PDF file from a HTML page
I'm using ABCPdf get a pdf from a some HTML code. While I was
I'm using Prawn to generate my PDF files from a HTML source. This HTML
In my production pipeline I need to generate a few hundred PDF from HTML.
I'm looking to generate a PDF document from HTML using the Winnovative PDF Converter
I am using html2pdf library in order to generate pdf from html file. I
I'm looking for a way to generate pdf files from html In order to
iam using dompdf to generate pdf file from html , the problem is the

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.