static void Main(string[] args) { DataTime dt = new DataTime(2020, 08, 19, 07, 23, 07); WriteLine("{0:yyyy-MM-dd HH:mm:ss (dddd)}", dt); CultureInfo ciKo = new CultureInfo("ko-KR); WriteLine(dt.ToString("yyyy-MM-dd tt hh:mm:ss (ddd)", ciKo)); }
public void InsertN1DataV3(string city, string routeName) { try { //橘9路線資料 RestClient client = new RestClient($"http://ptx.transportdata.tw/MOTC/v3/Bus/EstimatedTimeOfArrival/City/{city}/{routeName}?&$format=JSON"); IRestResponse response = GetResponse(client); if (response.StatusCode == HttpStatusCode.OK) { var APIResult = JsonConvert.DeserializeObject <BusN1DataV3>(response.Content); if (APIResult != null) { string RouteUID, RouteID, RouteName, SubRouteUID, SubRouteID, SubRouteName, DestinationStopID, DestinationStopName, StopUID, StopID, StopName, PlateNumb, ScheduledTime, CurrentStop; int Direction, EstimateTime, StopStatus, StopCountDown; DateTime DataTime, RecTime, TransTime; bool IsLastBus; string CreateTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"); string Result = string.Empty; foreach (N1DataV3 PTXData in APIResult.N1Datas) { RouteUID = PTXData.RouteUID; RouteID = PTXData.RouteID; RouteName = PTXData.RouteName.Zh_tw; SubRouteUID = PTXData.SubRouteUID; SubRouteID = PTXData.SubRouteID; SubRouteName = PTXData.SubRouteName.Zh_tw; Direction = PTXData.Direction; DestinationStopID = PTXData.DestinationStopID; DestinationStopName = PTXData.DestinationStopName.Zh_tw; StopUID = PTXData.StopUID; StopID = PTXData.StopID; StopName = PTXData.StopName.Zh_tw; PlateNumb = PTXData.PlateNumb; EstimateTime = PTXData.EstimateTime; ScheduledTime = PTXData.ScheduledTime; IsLastBus = PTXData.IsLastBus; CurrentStop = PTXData.CurrentStop; StopStatus = PTXData.StopStatus; StopCountDown = PTXData.StopCountDown; DataTime = PTXData.DataTime; RecTime = PTXData.RecTime; TransTime = PTXData.TransTime; Result = Result + "INSERT INTO N1DataV3(RouteUID, RouteID, RouteName, SubRouteUID, SubRouteID, SubRouteName, Direction, DestinationStopID, DestinationStopName, StopUID, StopID, StopName, PlateNumb, EstimateTime, ScheduledTime, IsLastBus, CurrentStop, StopStatus, StopCountDown, DataTime, RecTime, TransTime)" + "VALUES(" + " '" + RouteUID + "' " + ",'" + RouteID + "' " + ",'" + RouteName + "' " + ",'" + SubRouteUID + "' " + ",'" + SubRouteID + "' " + ",'" + SubRouteName + "' " + ",'" + Direction + "' " + ",'" + DestinationStopID + "' " + ",'" + DestinationStopName + "' " + ",'" + StopUID + "' " + ",'" + StopID + "' " + ",'" + StopName + "' " + ",'" + PlateNumb + "' " + ",'" + EstimateTime + "' " + ",'" + ScheduledTime + "' " + ",'" + IsLastBus + "' " + ",'" + CurrentStop + "' " + ",'" + StopStatus + "' " + ",'" + StopCountDown + "' " + ",'" + DataTime.ToString("yyyy/MM/dd HH:mm:ss") + "' " + ",'" + RecTime.ToString("yyyy/MM/dd HH:mm:ss") + "' " + ",'" + TransTime.ToString("yyyy/MM/dd HH:mm:ss") + "' " + ") ;"; } //寫入資料 if (Result != "") { SqlConnection connnew = new SqlConnection(strconnection); try { connnew.Open(); SqlCommand cmmdnew = new SqlCommand(Result, connnew); cmmdnew.ExecuteNonQuery(); } catch (Exception ex) { Console.WriteLine("N1DataV3 error "); Console.WriteLine(ex.Message); } finally { connnew.Close(); } } } } } catch (Exception e1) { Console.WriteLine(e1.Message); } }