convert this "1458480306" Into 20160320142506

convert this "1458480306" Into 20160320142506

Postby MarcoBoschi » Sun Mar 20, 2016 4:29 pm

Hi,
"1458480306.jpg" is a name of a pictures in my smartphone.
I have to rename it with this name 20160320142506.jpg


http://www.timestampconvert.com/?go2=true&offset=-1&timestamp=1458480306063&Submit=++++++Convert+to+Date++++++


YYYYMMDDHHMMSS.


Does exist a function?


Many thanks

Marco
Code: Select all  Expand view

FUNCTION MAIN
cName := "1458480306"

? MyConvert( cName )

RETURN NIL

FUNCTION Myconvert( cName )
LOCAL cReturn

cReturn := convert( cName )


RETURN cReturn

 
User avatar
MarcoBoschi
 
Posts: 1065
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

Re: convert this "1458480306" Into 20160320142506

Postby cnavarro » Sun Mar 20, 2016 4:48 pm

Try

Code: Select all  Expand view


? hb_Ttos( hb_DateTime() )

 
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6541
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: convert this "1458480306" Into 20160320142506

Postby MarcoBoschi » Sun Mar 20, 2016 6:26 pm

Many thanks
but I do not explay very wel the problem

This is the string to convert "1458480306"

Unix time, the number of seconds since 00:00:00 UTC on January 1, 1970

into this 20160320142506
or simply into

Date in your timezone*: 20/3/2016, 14:25:06

mucias gracias
User avatar
MarcoBoschi
 
Posts: 1065
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

Re: convert this "1458480306" Into 20160320142506

Postby mastintin » Sun Mar 20, 2016 9:36 pm

function Main()

local nSeconds:= 1458480306
local nfecha := secondstotime( nSeconds )
msginfo(nFecha)


return nil

//----------------------------------------------------------------//


function secondstotime( nSeconds )

local nDias:= int( nSeconds /( 60*60*24) )
local nResto := nseconds - nDias*60*60*24
local nNewDate := ctod("1/1/1970") + nDias
local nHoras := int(nResto/(60*60) )
local nMinutos

nResto := nResto - nHoras *60 *60
nHoras := nHoras + 1 // For UTC
nMinutos := int ( nResto / 60 )
nResto := nResto - nMinutos *60
nNewdate := dtos( nNewdate ) + strzero(nHoras,2,0)+ strzero(nMinutos,2,0) + strZero( nResto,2,0)
Return nNewDate
User avatar
mastintin
 
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm

Re: convert this "1458480306" Into 20160320142506

Postby MarcoBoschi » Mon Mar 21, 2016 9:31 am

Many Thanks!

marco
User avatar
MarcoBoschi
 
Posts: 1065
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

Re: convert this "1458480306" Into 20160320142506

Postby nageswaragunupudi » Thu Mar 24, 2016 9:34 am

Here is another approach, utilizing (x)Harbour's capabilities of datetime computations and also incorporating the timezone conversion implications.

Code: Select all  Expand view

function MyConvert( cUnixName )
return cFileSetExt( Left( TTOS( STOT( "19700101000000" ) + Val( cUnixName ) / ( 24 * 3600 ) + 1/24 ), 14 ), cFileExt( cUnixName ) )
 


? MyConvert( "1458480306.jpg" ) --> "20160320142506.jpg"

It may be worth examining each calculation involved in the above single line formula. Here it is:

Image

Now, a discussion about TimeZone adjustment and DST. In the above function I just added 1/24 which is +01:00, being the timezone of Italy when DST is not in use. When DST is in use it is going to be +02:00, i.e. 2/24 of a day. So, this forumla should also consider DST.

We need to use the TimeZone offset applicable to the converted UTC date but not the date when the function is called. That means we need to have a look up table.

Here is the revised function taking into account Italy's DST and TimeZone:
Code: Select all  Expand view

function MyConvertDST( cUnixName )

   local aDST := { ;
      { {^ 2014/03/30 01:00 }, {^ 2014/10/26 01:00 } }, ;
      { {^ 2015/03/29 01:00 }, {^ 2015/10/25 01:00 } }, ;
      { {^ 2016/03/27 01:00 }, {^ 2016/10/30 01:00 } }, ;
      { {^ 2017/03/26 01:00 }, {^ 2017/10/29 01:00 } }, ;
      { {^ 2018/03/31 01:00 }, {^ 2018/10/28 01:00 } }  }

   local tRet  := STOT( "19700101000000" ) + Val( cUnixName ) / ( 24 * 3600 ) // converted to UTC DateTime

   if AScan( aDST, { |a| tRet >= a[ 1 ] .and. tRet <= a[ 2 ] } ) > 0
      tRet  += 1/24   // Additional for DST
   endif

return cFileSetExt( Left( TTOS( tRet + 1/24 ), 14 ), cFileExt( cUnixName ) )
 

In above example, if 10 days are added, the result should not be "20160330142506.jpg" but should be "20160330152506.jpg"

We can test the revised function with this:
? MyConvert( "1459344306.jpg" ) --> "20160330142506.jpg"
? MyConvert( "1459344306.jpg" ) --> "20160330152506.jpg"
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10620
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: convert this "1458480306" Into 20160320142506

Postby nageswaragunupudi » Thu Mar 24, 2016 9:38 am

Day Light Savings:

I am from a tropical country India and we do not have Day Light savings adjustments. So I am not aware of the complexities that arise from this. I have some doubts and seek clarification / guidance from friends who are used to DLS

If an event is said to have happened on 25 Oct 2015 at 02:35 AM in Rome, Italy, how do we know if it happened before the clock was turned back or after? To my mind, this time refers to two different points of time separated by one hour. How do we distinctly identify which one it is?
In other words, if we want to convert this time into UTC, do we covert it as 25 Oct 2015 00:35 or 25 Oct 2015 01:35?
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10620
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: convert this "1458480306" Into 20160320142506

Postby Enrico Maria Giordano » Thu Mar 24, 2016 1:16 pm

nageswaragunupudi wrote:Here is another approach, utilizing (x)Harbour's capabilities of datetime computations and also incorporating the timezone conversion implications.

Code: Select all  Expand view

function MyConvert( cUnixName )
return cFileSetExt( Left( TTOS( STOT( "19700101000000" ) + Val( cUnixName ) / ( 24 * 3600 ) + 1/24 ), 14 ), cFileExt( cUnixName ) )
 


Very nice!

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: convert this "1458480306" Into 20160320142506

Postby MarcoBoschi » Thu Mar 24, 2016 3:03 pm

Many Thanks and Happy Easter dear Friends
User avatar
MarcoBoschi
 
Posts: 1065
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

Re: convert this "1458480306" Into 20160320142506

Postby Euclides » Thu Mar 24, 2016 4:13 pm

Thanks Rao, for the hint and explanation.
Regards, Euclides.
User avatar
Euclides
 
Posts: 156
Joined: Wed Mar 28, 2007 1:19 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 123 guests