There is a unixtimestamp (for example: 1421279818 = 01/14/2015 23:56:58 UTC).
It is necessary to make changes with the time, without touching the date.

Algorithmically, for example:

'14.01.2015' + ('23:56:58' * 20) и получить новые дату и время. 

When multiplied, the overflow time will go to the extra response days. If we multiply the whole value, naturally, the answer is incorrect, because it turns out:

 '14.01.2015 23:56:58' * 20 

We translate the time in seconds and multiply:

 86218 * 20 = 1724360 = 19Д 22:59:20 

Then we take the date:

 1421279818 - 86218 = 1421193600 

We add the result:

 1421193600 + 1724360 = 1422917960 

We get 02.02.2015 22:59:20

The question is: is there something standard for such calculations in Delphi or Php or do you need to invent your own?

In Delphi, you can translate, for example, in DateTime, divide it into components, then sum up them separately and monitor the overflows of days / months / years, take into account a leap year and so on ...

Easier, probably, and to work with unixtimestamp?

2 answers 2

And why change the data itself? You can just imagine how you need using the function Date() .

Here everything about this function is described: http://php.net/manual/ru/function.date.php

So, for example, you can display only the date (without time):

 Date ('d/m/Y',timestamp); 
  • Will it be displayed, and the operations will be carried out with them correctly? This is only for visualization, as I understand it ... The timestamp itself will remain unchanged - Isaev
  • @Isaev you write the result of this function into a variable and do whatever you want with this variable. Sam timestamp change and not necessary. You can present it at any time in any form thanks to the Date () function - JerryGreen

Multiply by 20, is it for days?

Use

 date('dmY', strtotime($time.' + 20 Days')); 
  • @ Sergey Baranov, no, this is not for days, this is for 20 ... i.e. speeding up time 20 times - Isaev
  • @Isaev uhhh .... "we speed up time by 20 times"? You are obviously doing something wrong. Tell us why you need it. If there is some time interval between two timestamps and it needs to be increased / decreased, then this task is solved much easier. - kot-da-vinci
  • @ kot-da-vinci, everything was easier, figured out, implemented ... As usual, I thought too hard) - Isaev
  • @Isaev write down your implementation as an answer and accept it as correct. - kot-da-vinci