-
Notifications
You must be signed in to change notification settings - Fork 1
/
StrUtils.cs
56 lines (46 loc) · 1.95 KB
/
StrUtils.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System;
using System.IO;
namespace UnderwaterVideo2
{
public static class StrUtils
{
public static string GetHMSString(DateTime dt)
{
return string.Format("{0:00}-{1:00}-{2:00}", dt.Hour, dt.Minute, dt.Second);
}
public static string GetHMSString()
{
return GetHMSString(DateTime.Now);
}
public static string GetYMDString()
{
return GetYMDString(DateTime.Now);
}
public static string GetYMDString(DateTime dt)
{
return string.Format("{0}-{1:00}-{2:00}", dt.Year, dt.Month, dt.Day);
}
public static string GetTimeDirTree(DateTime dt, string appPath, string targetPath, bool isCreate)
{
string fullDirecoryName = Path.Combine(Path.Combine(Path.GetDirectoryName(appPath), targetPath), GetYMDString(dt));
if (!Directory.Exists(fullDirecoryName) && isCreate)
Directory.CreateDirectory(fullDirecoryName);
return fullDirecoryName;
}
public static string GetTimeDirTree(string appPath, string targetPath, bool isCreate)
{
return GetTimeDirTree(DateTime.Now, appPath, targetPath, isCreate);
}
public static string GetTimeDirTreeFileName(DateTime dt, string appPath, string targetPath, string extension, bool isCreate)
{
string fullDirecoryName = GetTimeDirTree(dt, appPath, targetPath, isCreate);
string fileName = string.Format("{0}.{1}", GetHMSString(dt), extension);
return Path.Combine(fullDirecoryName, fileName);
}
public static string GetTimeDirTreeFileName(string appPath, string targetPath, string extension, bool isCreate)
{
DateTime dt = DateTime.Now;
return GetTimeDirTreeFileName(dt, appPath, targetPath, extension, isCreate);
}
}
}