Menu

Fashion Trendy
  • Drop Down

    • Abstract
    • Model
    • Techo
    • Options
  • Photography Pictures Product

    Drop Menu

    • Crystal
    • Digital
    • Graphs
    • Settings
  • Menu

    Stack Now | C, C++, Linux, Design Patterns etc

    • Home
    • Digital Art
      • Pics
        • SEO 1
        • SEO 2
      • CSS
        • CSS 1
        • CSS 2
        • CSS 3
        • CSS 4
        • CSS 5
      • Jquery
        • Jquery 1
        • Jquery 2
    • Fashion
      • Product 1
        • Sub Item
        • Sub Item
      • Product 2
        • Sub Item
        • Sub Item
    • Photography
    • Design
    Go
    Home » C » C++ » How to Print Time in Particular Format in C/C++?

    How to Print Time in Particular Format in C/C++?

    You can print time in any format using strftime function in C/C++.

    The function declaration is as below:
    size_t strftime (char* buf, int size, const char* format, const struct tm* timeptr);
    • buf is the pointer to buffer.
    • size is the sizeof(buf).
    • timeptr is pointer to struct tm.
    • format defines in which format the time to be printed. For example if you specify as "%D" it will print in MM/DD/YY date, equivalent to %m/%d/%y format. To know all the formats, refer here.
    Example:

    int main()
    {
    char buf[20];
    struct tm *tptr;
    time_t t(NULL);

    tptr = localtime(&t);

    strftime(buf, sizeof(buf), "%D", tptr);

    return 0;
    }
    yash
    Add Comment
    C C++
    Tuesday, April 15, 2014

    facebook

    twitter

    google+

    fb share

    About yash

    Related Posts
    ☺ Next Post >

    Menu
    • Home
    • C
    • C++
    • Linux
    • Design Patterns
    • Programming Tips

    Popular Posts

    • 8 C++ String Functions You Must Know!
      In C++, String is one of the most used class to represent a sequence of characters. String class is an instantiation of the basic_string c...
    • How to Print Time in Particular Format in C/C++?
      You can print time in any format using strftime function in C/C++. The function declaration is as below: size_t strftime (char* buf, i...
    • 2-Minute Guide for Patching and Generating a Patch File
      Many times in the project, you need to generate a patch file or patch the file to your project. This 2 minute guide will help you how to g...
    • How to Write Better Programs in C/C++?
      I have been coding for the past 7 years in a MNC and had experienced a lot of programming rules. Here I am sharing some of the tips with w...
    • Singleton Design Pattern - My View
      I had used singleton design pattern in one of my projects. And in this post I will express my views about it. Singleton design pattern i...

    Social Share

    Weekly Posts

    • 8 C++ String Functions You Must Know!
      In C++, String is one of the most used class to represent a sequence of characters. String class is an instantiation of the basic_string c...
    • How to Print Time in Particular Format in C/C++?
      You can print time in any format using strftime function in C/C++. The function declaration is as below: size_t strftime (char* buf, i...
    • 2-Minute Guide for Patching and Generating a Patch File
      Many times in the project, you need to generate a patch file or patch the file to your project. This 2 minute guide will help you how to g...
    • How to Write Better Programs in C/C++?
      I have been coding for the past 7 years in a MNC and had experienced a lot of programming rules. Here I am sharing some of the tips with w...
    • Singleton Design Pattern - My View
      I had used singleton design pattern in one of my projects. And in this post I will express my views about it. Singleton design pattern i...

    Like us On Facebook

    Labels

    • C
    • C++
    • Design Patterns
    • linux
    • Programming Tips

    Copyright Stack Now | C, C++, Linux, Design Patterns etc 2014 . Template Created by