[英]How can i create a file name that will include also the date and time of the first day and the last day?
I'm not sure yet how the format of the file name should be the idea is to make somehow the file name to be built from the first date and time of when the first file added to the List and the date time when it's creating the animated gif file: 我不确定文件名的格式应该是如何从第一个文件添加到列表中的第一个日期和时间以及创建文件时的日期时间开始以某种方式构建文件名动画gif文件:
private void CreateAnimatedGif(bool ToCreate)
{
if (ToCreate == false)
{
AnimatedGifFiles.Add(last_file);
}
else
{
for (int i = 0; i < AnimatedGifFiles.Count; i++)
{
if (!AnimatedGifFiles[i].Contains(last_file))
AnimatedGifFiles.Add(last_file);
}
if (AnimatedGifFiles.Count > 1)
{
unfreezWrapper1.MakeGIF(AnimatedGifFiles, AnimatedGifDirectory, 80, true);
}
AnimatedGifFiles = new List<string>();
}
}
This method is being called each X seconds only when a website provide new image each time and the image was download to my hard disk. 仅当网站每次提供新图像并将图像下载到我的硬盘时,才每X秒调用一次此方法。
Then the method can be called for hours sometimes even days 3-4 days. 然后可以调用该方法几个小时,有时甚至是3-4天。
As long as the variable ToCreate is false it will keep adding files to the List AnimatedGifFiles. 只要变量ToCreate为false,它将继续将文件添加到列表AnimatedGifFiles。 Then after some hours or it can be even some days the variable ToCreate is true and then it will create the Animated gif file.
然后几个小时甚至可能几天后,变量ToCreate为true,然后它将创建gif动画文件。
For now in this line i gave it only a directory: 现在在这一行中,我只给它一个目录:
unfreezWrapper1.MakeGIF(AnimatedGifFiles, AnimatedGifDirectory, 80, true);
AnimatedGifDirectory is a path with a directory. AnimatedGifDirectory是带有目录的路径。 But it should be with a file name in the end for exmaple: c:\\test\\AnimatedGifFile\\Animated.gif
但是它的结尾应该是文件名:c:\\ test \\ AnimatedGifFile \\ Animated.gif
But now it's only c:\\test\\AnimatedGifFile\\ 但是现在只有c:\\ test \\ AnimatedGifFile \\
I'm not sure how to create the file name using the first added file to the List date and time and the date and time when the Animated gif file was created. 我不确定如何使用列表日期和时间以及创建gif动画文件的日期和时间中添加的第一个文件来创建文件名。
Something like: 12/12/04_12/22/04.gif I want that the user will know according to the file name the dates of the event when the event started 12/12/04 and when it was ended 12/22/04 类似于:12/12 / 04_12 / 22 / 04.gif我希望用户根据文件名知道事件的开始日期(04/12/12)和结束的日期(12/22/04)。
And then after some hours or days again the method will be called so the next file name will be for example: 01/10/05_01/13/05.gif 然后几个小时或几天后,将再次调用该方法,因此下一个文件名将是例如:01/10 / 05_01 / 13 / 05.gif
And so on but i'm not sure how to create a file name with the first added file date time and in the end the date time and what kind of format of the file to make ? 依此类推,但是我不确定如何用第一个添加的文件日期时间以及最后的日期时间以及要制作哪种格式的文件来创建文件名?
Maybe something like: First-12/12/04_Last-12/22/04.gif Or maybe : Event-12/12/04-12/22/04.gif 可能类似于:First-12 / 12 / 04_Last-12 / 22 / 04.gif也许:Event-12 / 12 / 04-12 / 22 / 04.gif
I wanted to add also the time in each side when started and ended but that might make the file too long. 我还想在开始和结束时添加双方的时间,但这可能会使文件过长。
Or 要么
Maybe the easiest way will be to create for each event a directory for example: 也许最简单的方法是为每个事件创建一个目录,例如:
Event-12/12/04-12/22/04 事件12/12 / 04-12 / 22/04
And inside to create a shorter gif file. 并在里面创建一个较短的gif文件。
EDIT: I changed the format to match ISO 8601 编辑:我更改了格式以匹配ISO 8601
First, I would reommend that you use a date format that is easy to sort by: 2014_10_22, for example. 首先,我建议您使用一种易于排序的日期格式:例如2014_10_22。 File name format can then be :
2014_10_22__2014_10_23_1900.gif
2014-10-22__2014-10-23T1900.gif 文件名格式可以为:
2014_10_22__2014_10_23_1900.gif
2014-10-22__2014-10-23T1900.gif
or better for sorting (if it is possible that several files wikll be created in the same date):
2014_10_22__1600__56h.gif
2014-10-22T1600__56h.gif 或更好的排序方式(如果有可能在同一日期创建多个文件):
2014_10_22__1600__56h.gif
2014-10-22T1600__56h.gif
(where1600 is 4pm - start time of the file, and 56 is the length of time in hours) (其中1600是4pm-文件的开始时间,而56是以小时为单位的时间长度)
Change your function this way. 以此方式更改您的功能。 You can adjust the way the dates are formatted.
您可以调整日期的格式。 Note the
dateTime
member variable. 注意
dateTime
成员变量。
private List<string> AnimatedGifFiles;
private DateTime startTime; // new!!
private void CreateAnimatedGif(bool ToCreate)
{
if(AnimatedGifFiles.Count == 0) // new!!
startTime = DateTime.Now;
if (ToCreate == false)
{
AnimatedGifFiles.Add(last_file);
}
else
{
for (int i = 0; i < AnimatedGifFiles.Count; i++)
{
if (!AnimatedGifFiles[i].Contains(last_file))
AnimatedGifFiles.Add(last_file);
}
if (AnimatedGifFiles.Count > 1)
{
string outputFile = System.IO.Path.Combine( // new!!
AnimatedGifDirectory,
string.Format(
System.Globalization.CultureInfo.InvariantCulture,
"Event-{0:yyyy-MM-dd}-{1:yyyy-MM-dd}.gif", startTime, DateTime.Now));
unfreezWrapper1.MakeGIF(AnimatedGifFiles, outputFile, 80, true); //new!!
}
AnimatedGifFiles = new List<string>();
}
}
Try this: 尝试这个:
private string startDateTime = "";
private void CreateAnimatedGif(bool ToCreate)
{
string endDateTime;
if (ToCreate == false)
{
if(startDateTime == ""){startDateTime = DateTime.Now.ToString("yyyy-MM-ddTHH'h'mm'm'ss's'_");}
AnimatedGifFiles.Add(last_file);
}
else
{
if (!AnimatedGifFiles.Contains(last_file))
{
AnimatedGifFiles.Add(last_file);
}
if (AnimatedGifFiles.Count > 1)
{
endDateTime = DateTime.Now.ToString("yyyy-MM-ddTHH'h'mm'm'ss's.gif'");
unfreezWrapper1.MakeGIF(AnimatedGifFiles, AnimatedGifDirectory+ startDateTime + endDateTime, 80, true);
}
startDateTime = "";
//You don't create a new list. Clear the existing one
if(AnimatedGifFiles.Count != 0){AnimatedGifFiles.Clear();}
}
}
I did not clearly understand your code, but i think you trying to do something like that: 我不太清楚您的代码,但我认为您正在尝试执行以下操作:
private void CreateAnimatedGif(bool ToCreate) {
string dateOfCreate;
if (ToCreate == false)
{
if(AnimatedGifFiles.Count == 0) // that means it's the first element in the list
{
dateOfCreate = DateTime.Now.ToString();
}
AnimatedGifFiles.Add(last_file);
}
else
{
if(AnimatedGifFiles.Count == 0) // that means it's the first element in the list
{
dateOfCreate = DateTime.Now.ToString();
}
if (!AnimatedGifFiles.Contains(last_file))
{
AnimatedGifFiles.Add(last_file);
}
if (AnimatedGifFiles.Count > 1)
{
unfreezWrapper1.MakeGIF(AnimatedGifFiles, AnimatedGifDirectory + dateOfCreate + DateTime.Now.ToString(), 80, true);
}
AnimatedGifFiles = new List<string>();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.