Time Library | C Programming Tutorial

แชร์
ฝัง
  • เผยแพร่เมื่อ 28 ม.ค. 2025

ความคิดเห็น •

  • @warplanner8852
    @warplanner8852 7 หลายเดือนก่อน +10

    46 years as a software developer (over half doing C/C++) and this is the most succinct and complete example of the UNIX/LINUX time code without the pages and pages of boilerplate. You are a true craftsman!

  • @khetanshusingh9059
    @khetanshusingh9059 8 หลายเดือนก่อน +6

    I've been searching a video to print current time of my system from past 2 days.
    Then, suddenly your video got recommended today and I must say that this video is an upgrade of what I wanted in first place.
    Best tutorial on this topic.❤
    Thanks a lot.

  • @SymbioteV3
    @SymbioteV3 3 ปีที่แล้ว +18

    Thank you so much for making this video! I can't even explain how helpful this was.

    • @PortfolioCourses
      @PortfolioCourses  3 ปีที่แล้ว +1

      You’re welcome! I’m very glad to hear it was helpful for you. :-)

  • @fifaham
    @fifaham ปีที่แล้ว +3

    The "strftime()" at @16:50 comes in very handy for embedded designers because they can specifically tailor the output based on various features requirements. I will definitely consider using it in my next project. In embedded design we usually use a chip called Real-Time-Clock (RTC) and follow instructions on data sheet to how to format the output. This makes it very powerful to interface the RTC of the PC with the Embedded device for real embedded action.

  • @u12blue
    @u12blue 2 ปีที่แล้ว +1

    I've been looking for a channel like this for a very long time!!! Thank you so much for making this video!!!

  • @thundercloud-7913
    @thundercloud-7913 2 ปีที่แล้ว +1

    very good video, been looking after content like this of c programming during weeks and wasn't able to find anything good enough like this

    • @PortfolioCourses
      @PortfolioCourses  2 ปีที่แล้ว

      Thank you very much for the kind feedback, I'm glad to hear you enjoyed the video! :-D

  • @mortenlund1418
    @mortenlund1418 7 หลายเดือนก่อน

    You are eminent at doing this stuff! Thanks for sharing. Very much.

  • @velozdrums
    @velozdrums 2 ปีที่แล้ว

    never subscribed so fast before

    • @PortfolioCourses
      @PortfolioCourses  2 ปีที่แล้ว

      Thank you so much Gabriel, that's awesome!!! 🙂

  • @towtruckn
    @towtruckn 2 ปีที่แล้ว

    Thank you for the great video I was playing around with this for hours and learnt so much. With the strftime() function all of the format specifiers are identical to those given in the man page for the date command. The specifiers for its default output are "%a %d %b %Y %X %Z" if anyone is interested. Hope this helps

    • @PortfolioCourses
      @PortfolioCourses  2 ปีที่แล้ว +1

      You're welcome and thank you for sharing this! :-)

  • @fifaham
    @fifaham ปีที่แล้ว

    @20:24 This is very useful to measure events or signal parameters, we call it Timer Capture and Compare in Embedded design, where the MCU counts the number of clocks elapsed between the start of measuring time and the end of measurement, or counting the number of clocks over the incident latency. We use the Capture and Compare to also create certain wave forms with specific parameters and accuracy of near microsecond.

  • @shvideo1
    @shvideo1 3 ปีที่แล้ว +1

    I echo the other comments. Excellent C tutorial. Thank you for putting it together.

  • @TheSquareClasses
    @TheSquareClasses 2 ปีที่แล้ว

    You are awesome.
    You explained it very simply.
    I am no words for thanking you.
    Love you man ❤️❤️.

    • @PortfolioCourses
      @PortfolioCourses  2 ปีที่แล้ว

      Aww I'm so glad you enjoyed it, you're very welcome! 😀

  • @cd-stephen
    @cd-stephen 2 ปีที่แล้ว

    great vid - love how you described epoch

    • @PortfolioCourses
      @PortfolioCourses  2 ปีที่แล้ว

      Thank you for the kind feedback! 🙂

    • @cd-stephen
      @cd-stephen 2 ปีที่แล้ว

      @@PortfolioCourses any chance of a series of c or cpp vids on making drivers in linux

    • @PortfolioCourses
      @PortfolioCourses  2 ปีที่แล้ว +1

      @@cd-stephen Maybe one day I could do an introductory video on making drivers, but that's not my specialty so that's about as far as I could go with it I think. 🙂

  • @arjunmandavkar8597
    @arjunmandavkar8597 3 ปีที่แล้ว +3

    Very useful. Thank you man.

    • @PortfolioCourses
      @PortfolioCourses  3 ปีที่แล้ว

      Glad to hear you enjoyed it, and you're welcome! :-D

  • @vicsteiner
    @vicsteiner 7 หลายเดือนก่อน

    I just put sleep(1) between the start and end clocks expecting the total after to around 1.0s but I got much smaller values. What am I missing. Also if I execute the program multiple times the value for total varies even though sleep(1) should a constant time. Are the clock ticks not constant? Or maybe the waiting that the sleep function executes does not prevent the next clock to be executed somehow? Ah, so if sleep pauses the execution of a program would that mean that it stops somehow counting the clock ticks? so the value for the end clock is then not the one for the amount of ticks that would have been executed in the 1 sec equivalent?

  • @sigmage5345
    @sigmage5345 3 ปีที่แล้ว +1

    Thanks for this awesome and useful video!

  • @saboten7584
    @saboten7584 2 ปีที่แล้ว

    Thanks for the Amazing Lectures!

  • @alonsomadronal2919
    @alonsomadronal2919 2 ปีที่แล้ว

    Cool video! I really needed it, thanks!

  • @dewaldesterhuysen712
    @dewaldesterhuysen712 2 ปีที่แล้ว

    This helped, thank you for the time and effort.

    • @PortfolioCourses
      @PortfolioCourses  2 ปีที่แล้ว

      You're welcome Dewald, I'm glad to hear that it helped! :-)

  • @Aysx.
    @Aysx. 10 หลายเดือนก่อน

    How can i calculate time on my own only using time () ?
    Without using any other Libraries and functions

  • @thomaschurch1969
    @thomaschurch1969 ปีที่แล้ว

    Awesome video, very well done.

  • @abuaisha93
    @abuaisha93 3 ปีที่แล้ว +1

    this vid is awesome. keep going

  • @golladhanushkumar2991
    @golladhanushkumar2991 2 ปีที่แล้ว

    Thank you very much for making this video ... It's helped me a lot 😊

    • @PortfolioCourses
      @PortfolioCourses  2 ปีที่แล้ว

      You’re welcome! I’m glad to hear it helped you! :-)

  • @nrdfoss
    @nrdfoss 2 ปีที่แล้ว

    best time tutorial on yt

    • @PortfolioCourses
      @PortfolioCourses  2 ปีที่แล้ว

      Thank you very much! :-D

    • @nrdfoss
      @nrdfoss 2 ปีที่แล้ว

      @@PortfolioCourses rather i should thank you, every tutorial or doc that i found was just barely not what i was looking for lol

    • @nrdfoss
      @nrdfoss 2 ปีที่แล้ว

      or too hard for me to read

    • @PortfolioCourses
      @PortfolioCourses  2 ปีที่แล้ว

      Haha well I’m glad to hear this one helped you out! :-)

  • @leythecg
    @leythecg ปีที่แล้ว

    Great presentation and content! 👍👍👍

  • @exp3rim
    @exp3rim 2 ปีที่แล้ว +1

    Thank you very much. It was very helpful.

  • @HamzahChaudhry
    @HamzahChaudhry 11 หลายเดือนก่อน

    ty for the vid, def helped me out for my coding lab lol

    • @PortfolioCourses
      @PortfolioCourses  11 หลายเดือนก่อน

      You’re welcome, that’s excellent to hear I helped you out! :-)

  • @hilacohen230
    @hilacohen230 2 ปีที่แล้ว

    Thanks for straightforward explanation ! Is there a way to see the current time (since EPOCH) in milliseconds?

    • @PortfolioCourses
      @PortfolioCourses  2 ปีที่แล้ว +1

      I actually didn't know the answer to this myself, so I had to Google it, and this Stackoverflow thread offers a couple solutions... a possible function use and a POSIX library function that can be used: stackoverflow.com/questions/1952290/how-can-i-get-utctime-in-millisecond-since-january-1-1970-in-c-language. So I would try our these methods. I think maybe I'll make a video on this someday. :-)

    • @Ahmadkhan-sm2qd
      @Ahmadkhan-sm2qd 9 หลายเดือนก่อน

      For milliseconds, you can use chrono C++

  • @trikkee
    @trikkee ปีที่แล้ว

    How about the theory of the relativity where time count down slowly ?
    Thank you for sharing.

    • @PortfolioCourses
      @PortfolioCourses  ปีที่แล้ว

      Hahaha someone should make that library. :-) You’re welcome!

  • @ismailchiba7002
    @ismailchiba7002 2 ปีที่แล้ว

    i have a question what does seed mean like when we want to use the srand fuction : srand(time(0))

    • @PortfolioCourses
      @PortfolioCourses  2 ปีที่แล้ว +1

      We seed the random number generator to ensure that it gives us different random numbers each time we run the program. We typically seed it with a value that will be unique each time we run our program, like for example the current time. This video on random number generation explains more: th-cam.com/video/Mp3eGLX-OpY/w-d-xo.html. :-)

    • @ismailchiba7002
      @ismailchiba7002 2 ปีที่แล้ว

      @@PortfolioCourses thanks 😁

    • @PortfolioCourses
      @PortfolioCourses  2 ปีที่แล้ว

      @@ismailchiba7002 You're welcome! 🙂

  • @ZinWesam
    @ZinWesam 15 ชั่วโมงที่ผ่านมา

    Thank u man from syria 🥰

  • @angeltorresloya
    @angeltorresloya ปีที่แล้ว

    Thank you, I learned a lot fo things

  • @gurmukhsingh8190
    @gurmukhsingh8190 2 ปีที่แล้ว

    Hi I tried the code from this video in the Arduino IDE. I want to show the current time and date. However, the output is showing the time and date from January 1970. Any ideas on how I can fix this code?
    void loop()
    {
    time_t now = time(NULL);
    char *string_now = ctime(&now);
    Serial.println(string_now);
    }

    • @PortfolioCourses
      @PortfolioCourses  2 ปีที่แล้ว +1

      Great question Gurmukh! 🙂 I'm not sure exactly how the time.h library will work with Arduino and the Ardunio IDE, or whether it will work at all. There is this other time library for Arduion that people seem to mention online, maybe this would be better to use instead of time.h: github.com/PaulStoffregen/Time.

    • @gurmukhsingh8190
      @gurmukhsingh8190 2 ปีที่แล้ว

      @@PortfolioCourses Thank you so much for the quick response. The time libraries from this link that you have provided look useful I will check them out. Thank you so much you for all your help! 🙂

    • @PortfolioCourses
      @PortfolioCourses  2 ปีที่แล้ว +1

      @@gurmukhsingh8190 You're welcome! 🙂

  • @ismailchiba7002
    @ismailchiba7002 2 ปีที่แล้ว

    Thank you for the great video

  • @radio_electronics4047
    @radio_electronics4047 2 ปีที่แล้ว

    sleep(2) does not work for me. It creates an endless loop...
    Edit: Ok, the problem was that I didn't put a
    at the end of a printf statement, and C somehow cant write into the same line again,
    when there was a sleep in between.

  • @johnpipe362
    @johnpipe362 2 ปีที่แล้ว

    Very Helpful.

    • @PortfolioCourses
      @PortfolioCourses  2 ปีที่แล้ว

      I’m glad to hear it helped you out John! :-)

  • @mjsaedy6637
    @mjsaedy6637 ปีที่แล้ว

    "go through the functions one at a time"
    Pun intended?

  • @haripriyaraja1890
    @haripriyaraja1890 ปีที่แล้ว

    Thank you so much

  • @junpuyinwei4020
    @junpuyinwei4020 ปีที่แล้ว

    谢谢!😜

  • @printdaniel
    @printdaniel 2 ปีที่แล้ว

    Thanks you!!!.

  • @maurod6180
    @maurod6180 2 ปีที่แล้ว

    great

  • @GeeKay870
    @GeeKay870 9 หลายเดือนก่อน

    Tyy

  • @tdoc666___
    @tdoc666___ ปีที่แล้ว

    this topic took a long *time* to explain, what a bad joke...

  • @Bruh-nj3bv
    @Bruh-nj3bv 2 ปีที่แล้ว

    2 secs 😈

  • @handsomeman-pm9vy
    @handsomeman-pm9vy ปีที่แล้ว

    WTF? How many libraries are needed for a simple program?
    C sucks!

    • @PortfolioCourses
      @PortfolioCourses  ปีที่แล้ว

      Hahahaha I hear you… C is sort of the “grandpa” of programming languages, it’s old and does things in old ways and needs some extra help to get around. :-)

  • @miguelcosta4450
    @miguelcosta4450 ปีที่แล้ว

    Portfolio can you help me? You have discord?

    • @PortfolioCourses
      @PortfolioCourses  ปีที่แล้ว +1

      I do not have a discord and I am not able to provide tutoring right now due to time constraints, but I do try to answer questions that are posted as comments on videos. :-)