I have developed a windows service. When I debug the service, it works fine.
But when I install it & start the service it throws exception for datetime
when storing into the MYSQL database. Since the format of the datetime on my system is different from the one on the MySQL database.
My system datetime
format is mm-dd-yyyy HH:mm:ss
. MYSQL does not accept this mm/dd/yyyy HH:mm:ss tt
format for the datetime column
which format will be chosen by window service?
Use SQL parameters to transfer date/time values. This way, you can simply pass a datetime object instead of its string representation.
尝试使用格式yyyy-MM-dd HH:mm:ss tt
Check here for details on formatting the DateTime, see the example at the bottom of the page.
Quote from page:
// This example displays the following output to the console:
// d: 6/15/2008
// D: Sunday, June 15, 2008
// f: Sunday, June 15, 2008 9:15 PM
// F: Sunday, June 15, 2008 9:15:07 PM
// g: 6/15/2008 9:15 PM
// G: 6/15/2008 9:15:07 PM
// m: June 15
// o: 2008-06-15T21:15:07.0000000
// R: Sun, 15 Jun 2008 21:15:07 GMT
// s: 2008-06-15T21:15:07
// t: 9:15 PM
// T: 9:15:07 PM
// u: 2008-06-15 21:15:07Z
// U: Monday, June 16, 2008 4:15:07 AM
// y: June, 2008
//
// 'h:mm:ss.ff t': 9:15:07.00 P
// 'd MMM yyyy': 15 Jun 2008
// 'HH:mm:ss.f': 21:15:07.0
// 'dd MMM HH:mm:ss': 15 Jun 21:15:07
// '\Mon\t\h\: M': Month: 6
// 'HH:mm:ss.ffffzzz': 21:15:07.0000-07:00
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.