---
# System prepended metadata

title: '**DateTimeExtensions**'
tags: [PublicClass, ' DateTime']

---

---
tags: PublicClass, DateTime
author: Anderson
---

###### tags: `PublicClass` `DateTime`
# **DateTimeExtensions**

## :memo:檔案位置
![](https://i.imgur.com/GLOrfNw.png)

---
## :memo:說明
1. ToAppDateFormatString()
1. ToAppDateTimeFormatString()

這兩個方法看起來沒甚麼差別

主要是抓取app.config裡的**datestringformat** 和 **datetimestringformat**來當format的內容

或許可以用來設定**yyyy/MM/dd** 和 **yyyy/MM/dd 23:59:59**

---
## :memo:Code
```csharp=
public static string ToAppDateFormatString(this DateTime datetime)
{
    if (!MyUtility.Check.Empty(Sci.Env.Cfg.DateStringFormat))
    {
        return datetime.ToString(string.Format("{0}", Sci.Env.Cfg.DateStringFormat));
    }

    return datetime.ToString();
}

public static string ToAppDateTimeFormatString(this DateTime datetime)
{
    if (!MyUtility.Check.Empty(Sci.Env.Cfg.DateTimeStringFormat))
    {
        return datetime.ToString(string.Format("{0}", Sci.Env.Cfg.DateTimeStringFormat));
    }
    return datetime.ToString();
}
```