#1 2021-06-21 05:42

Bingman
Member
Registered: 2021-06-21
Posts: 14

How to rename Unix Time Stamp to date time format?

I have some files named as:

1621184624 - xxxx.jpg

...

I just want to replace the time stamp to date time, like:

2021-05-16 - xxxx.jpg

I have already searched the 'timestamp', but not seeing anything related to what I'm trying to do.

In addition, I am not familiar with the 'Pascal Script', so would like to ask help from here,

thanks.

Offline

#2 2021-06-21 10:38

eR@SeR
Senior Member
From: Земун, Србија
Registered: 2008-01-23
Posts: 353

Re: How to rename Unix Time Stamp to date time format?

Hi,

Please try following Pascal Script rule if works for your files:

var
  DateTime: TDateTime;
  Parts: TStringsArray;

begin
  Parts := SubMatchesRegEx(WideExtractBaseName(FileName), '(162\d+)(.+)', false);
  If (Length(Parts) <=0) then exit;
  DateTime := UnixToDateTime(StrToInt64(Parts[0]));
  FileName := FormatDateTime('yyyy-mm-dd', DateTime) + Parts[1] + WideExtractFileExt(FileName);
end.

TRUTH, FREEDOM, JUSTICE and FATHERLAND are the highest morale values which human is born, lives and dies for!

Offline

#3 2021-06-21 11:13

Bingman
Member
Registered: 2021-06-21
Posts: 14

Re: How to rename Unix Time Stamp to date time format?

eR@SeR wrote:

Hi,

Please try following Pascal Script rule if works for your files:

var
  DateTime: TDateTime;
  Parts: TStringsArray;

begin
  Parts := SubMatchesRegEx(WideExtractBaseName(FileName), '(162\d+)(.+)', false);
  If (Length(Parts) <=0) then exit;
  DateTime := UnixToDateTime(StrToInt64(Parts[0]));
  FileName := FormatDateTime('yyyy-mm-dd', DateTime) + Parts[1] + WideExtractFileExt(FileName);
end.

Wow, awesome,it works!Very appreciate!

seems that I need to learn some programming, LOL!

And I have a small question:

If the beginning is not 162, but other numbers, how to deal with it?

As shown in the figure, i have many files of different years.

timestamp

Offline

#4 2021-06-21 11:22

eR@SeR
Senior Member
From: Земун, Србија
Registered: 2008-01-23
Posts: 353

Re: How to rename Unix Time Stamp to date time format?

You're welcome. Replace '(162\d+)(.+)' part in line 6 with '(\d+)(.+)' i.e. just remove 162 and it should work smile


TRUTH, FREEDOM, JUSTICE and FATHERLAND are the highest morale values which human is born, lives and dies for!

Offline

#5 2021-06-21 11:27

Bingman
Member
Registered: 2021-06-21
Posts: 14

Re: How to rename Unix Time Stamp to date time format?

eR@SeR wrote:

You're welcome. Replace '(162\d+)(.+)' part in line 6 with '(\d+)(.+)' i.e. just remove 162 and it should work smile

Thanks buddy, big help!

Offline

#6 2021-06-21 11:31

eR@SeR
Senior Member
From: Земун, Србија
Registered: 2008-01-23
Posts: 353

Re: How to rename Unix Time Stamp to date time format?

I'm not sure if there is Unix timestamp format in Reformat Date rule. If not, maybe it can be added smile


TRUTH, FREEDOM, JUSTICE and FATHERLAND are the highest morale values which human is born, lives and dies for!

Offline

#7 2021-06-21 11:51

Bingman
Member
Registered: 2021-06-21
Posts: 14

Re: How to rename Unix Time Stamp to date time format?

eR@SeR wrote:

I'm not sure if there is Unix timestamp format in Reformat Date rule. If not, maybe it can be added smile

I don't know much about timestamp, but the date after conversion is right, big_smile

Last edited by Bingman (2021-06-21 11:52)

Offline

Board footer

Powered by FluxBB