datetime-format

How to get yesterday's date in a particular format?

痴心易碎 提交于 2019-12-20 05:10:32
问题 I need to set Today and yesterday's date in a variable in a fixed format YYYYMMDD . For today date, when i did SET TODAY=%date:~10,4%%date:~4,2%%date:~7,2% it worked and displayed '20190426'. But how to set yesterday's date so I get it in the format - 20190425 ? 回答1: Update The original unix and linux tags were later changed to cmd and batch-file, which this Linux / Bash / sh solution won't apply to. To get yesterday's date: $ date +%Y%m%d --date yesterday 20190425 To get it into a var: $ var

How to compare two datetime in javascript?

我的梦境 提交于 2019-12-20 04:59:31
问题 I tried create markers by JSON parse from C #.I have a small problem about datetime compare in javascript. var nowDate= new Date(); var LastTenMin= new Date(nowDate.getFullYear(), nowDate.getMonth(), nowDate.getDate(),nowDate.getHours(),nowDate.getMinutes()- 10); var Time1= data2.LastRecordTime; var image2; var status; if (new Date(Time1) < new Date(LastTenMin)) { image2 = '/Images/truckOnline.png'; status = "Truck is online."+"\n"+"Last seen:"+" "+Time1, } else { image2 = '/Images

Convert from String to Date throws Unparseable date exception [duplicate]

折月煮酒 提交于 2019-12-20 02:52:45
问题 This question already has answers here : Java - Unparseable date (2 answers) Closed 6 years ago . I want to convert a Date to a String but I have some problems. My code is this: SimpleDateFormat formato = new SimpleDateFormat( "EEE MMM dd HH:mm:ss z yyyy"); String hacer = "Fri Nov 01 10:30:02 PDT 2013"; Date test = null; test = formato.parse( hacer); System.out.println("prueba===>" + test); But nothing something is wrong eclipse shows me this error: Unparseable date: "Fri Nov 01 10:30:02 PDT

Issue DateTime.ToString with string format “M” in .NET

落爺英雄遲暮 提交于 2019-12-19 13:49:05
问题 I have a problem with the string format of DateTime. I think it is bug in MS. Can you explain it, and what is wrong? class Program { static void Main(string[] args) { Console.WriteLine(DateTime.Now.ToString("M"));//return 07 July <---- WRONG, SEE MSDN Console.WriteLine(DateTime.Now.ToString(".M"));//return .7 <---- GOOD Console.ReadKey(); } } MSDN 回答1: From The "M" Custom Format Specifier If the "M" format specifier is used without other custom format specifiers , it is interpreted as the "M"

MySQL convert between two date format

只愿长相守 提交于 2019-12-19 11:54:34
问题 The user will enter the date in this format : 17-Feb-2017 and the date stored in mysql db is in this format : 2015-02-17 00:00:00 what I tried to do is SELECT * FROM insurance where DATE_FORMAT(in_date,'%d-%b-%Y') > '17-Feb-2017'; DATE_FORMAT(in_date,'%d-%b-%Y') return the date in this format : 17-Feb-2017 but that not working !! any suggestions ? 回答1: Convert the input to a date type and the column value too: SELECT * FROM insurance where date(in_date) > STR_TO_DATE('17-Feb-2017','%d-%b-%Y')

splitting date and time in data frame

本秂侑毒 提交于 2019-12-19 11:22:11
问题 I have a column list of dates in data frame with date format 201001011200 as %Y%m%d%H%M . I wanted to split them as %Y%m%d and %H%M as Date and Time. I tried to as.Date(data$Date,origin = "1970-01-01") but I got an error message Error in charToDate(x) : character string is not in a standard unambiguous format The class of the date is numeric . So I tried to convert it to character and applied the above as.Date function but was not helpful. Any idea? Thank you in advance. EDIT Here is a sample

Parsing a complicated string as DateTime

折月煮酒 提交于 2019-12-19 09:56:42
问题 Can someone tell me how should I approach converting the following format to a proper DateTime object? 11:50:46 AM on Wednesday, October 19, 2011 回答1: string s = "11:50:46 AM on Wednesday, October 19, 2011"; DateTime dateTime = DateTime.ParseExact(s, "hh:mm:ss tt on dddd, MMMM dd, yyyy", CultureInfo.InvariantCulture); 来源: https://stackoverflow.com/questions/11433480/parsing-a-complicated-string-as-datetime

Format time as “24-hour Military Time”?

橙三吉。 提交于 2019-12-19 04:12:27
问题 I am updating some SQL Server 2000 code to SQL Server 2008R2, and there is function that looks a lot like this for converting the time into 24 hour format. What is a cooler/more clever way to do that in T-SQL? 回答1: If all you want is just military time: SELECT CONVERT(VARCHAR(8), GETDATE(), 108) AS MilitaryTime 回答2: If you want time till second, then use this: SELECT GETDATE() 'Today', CONVERT(VARCHAR(8), GETDATE(), 108) 'hh:mi:ss' IF you want time till millisecond, then use this: SELECT

Converting PeriodIndex to DateTimeIndex?

人盡茶涼 提交于 2019-12-19 03:14:10
问题 I have a question regarding converting a tseries.period.PeriodIndex into a datetime. I have a DataFrame which looks like this: colors country time_month 2010-09 xxx xxx 2010-10 xxx xxx 2010-11 xxx xxx ... time_month is the index. type(df.index) returns class 'pandas.tseries.period.PeriodIndex' When I try to use the df for a VAR analysis (http://statsmodels.sourceforge.net/devel/vector_ar.html#vector-autoregressions-tsa-vector-ar), VAR(mdata) returns: Given a pandas object and the index does

Why does DisplayFormat with DataFormatString changes “/” (slash) to “-” (dash)?

不羁的心 提交于 2019-12-18 12:57:40
问题 I'm using the following code // Model [DisplayFormat( ApplyFormatInEditMode = true, DataFormatString = "{0:dd/MM/yyyy}")] public DateTime StartDate { get; set; } // View @Html.EditorFor(model => model.StartDate) to format the StartDate but the result is xx-xx-xxxx instead of xx/xx/xxxx . How can I solve this and always use the xx/xx/xxxx format? UPDATE: Changing the culture to en-US seems to work: var culture = new CultureInfo(userCulture); System.Threading.Thread.CurrentThread.CurrentCulture