# How to get the time when button pressed?

**URL:** <https://forums.kodeco.com/t/how-to-get-the-time-when-button-pressed/81619>\
**Category:** Swift\
**Created:** [September 12, 2019, 8:37pm UTC](https://forums.kodeco.com/t/how-to-get-the-time-when-button-pressed/81619 "2019-09-12T20:37:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![refika](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/refika/32/83680_2.png) [@refika](https://forums.kodeco.com/u/refika)\
**Post date:** [September 12, 2019, 8:37pm UTC](https://forums.kodeco.com/t/how-to-get-the-time-when-button-pressed/81619/1 "2019-09-12T20:37:40Z")

</div>

I am making a calculation app. I get the results to tableview as array and save them in a viewcontroller. But i couldn’t figure out how to get the time when user make a calculation (button pressed). Can you refer me something?

---

<div class="post-metadata">

**Author:** ![zablanc](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/zablanc/32/81719_2.png) [@zablanc](https://forums.kodeco.com/u/zablanc)\
**Post date:** [September 12, 2019, 9:00pm UTC](https://forums.kodeco.com/t/how-to-get-the-time-when-button-pressed/81619/2 "2019-09-12T21:00:33Z")

</div>

Not sure what you’re asking? To get the time when the button is pressed, just initialize Date(). What did you want to do with it, show the time when the calculation was made?

---

<div class="post-metadata">

**Author:** ![refika](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/refika/32/83680_2.png) [@refika](https://forums.kodeco.com/u/refika)\
**Post date:** [September 15, 2019, 6:19pm UTC](https://forums.kodeco.com/t/how-to-get-the-time-when-button-pressed/81619/3 "2019-09-15T18:19:25Z")

</div>

Yes I want to show the time when calculation was made. I want this because I will make a screen like History / Log .

---

<div class="post-metadata">

**Author:** ![stromyc](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/stromyc/32/81494_2.png) [@stromyc](https://forums.kodeco.com/u/stromyc)\
**Post date:** [September 20, 2019, 11:58am UTC](https://forums.kodeco.com/t/how-to-get-the-time-when-button-pressed/81619/4 "2019-09-20T11:58:50Z")

</div>

Sounds like you want a “time-stamp”? This would be a recorded time when you save values to your table. You would need to use the NSDate class, format it to the date style you want and assign it to your table view cell.

---

<div class="post-metadata">

**Author:** ![system](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@system](https://forums.kodeco.com/u/system)\
**Post date:** [February 26, 2020, 12:37pm UTC](https://forums.kodeco.com/t/how-to-get-the-time-when-button-pressed/81619/5 "2020-02-26T12:37:41Z")

</div>

Closed on February 26, 2020, 12:37pm UTC

This topic was automatically closed after 166 days. New replies are no longer allowed.
