date-format

Format a datetime string to time only

别来无恙 提交于 2019-12-05 16:17:54
I'm retrieving a datetime from a SQLite DB which comes out in the format... 2011-01-24 02:45:00 In C# I can simply use DateTime.Parse("2011-01-24 02:45:00").ToString("HH:mm") in order to get the string 02:45 Is their a way I can I do this in Android/Java? My code in my Android app looks like this... // dateStr below is logging as correctly being yyyy-MM-dd HH:mm:ss format String dateStr = cursor.getString(cursor.getColumnIndex("start_time")); SimpleDateFormat sdf = new SimpleDateFormat("HH:mm"); String shortTimeStr = sdf.format(dateStr); // <-- throws IllegalArgumentException EDIT: Thanks to

Converting multiple columns in an R dataframe to Date Format

喜欢而已 提交于 2019-12-05 15:16:02
I have a large datafile where all the dates have been loaded as charaters. I would like to change all the Dates columns to date format. Most of the dates have "%y%m%d" format, some have "%Y%m%d" format. There are 25 columns of dates, so changing each one individually is inefficient. I can do df$DATE1 <- as.Date(df$DATE1, format ="%y%m%d") df$DATE2 <- as.Date(df$DATE2, format ="%y%m%d") etc., but very bad coding. I tried the following code, but is is not working. This assumes all of the dates are of the format "%y%m%d". Using grep("DATE", names(df)) will get all the Dates columns df[ , grep(

check format of date with moment.js

折月煮酒 提交于 2019-12-05 15:10:30
问题 I am taking input from calendar in my screen which is of this type DD-MMM-YYYY HH:mm a but user can provide date from keyboard. Now I have to check whether user has provided the date in correct format or not. I am heavily using moment.js in my application and validating it like this if(angular.equals(moment(scope.modelValue).format('DD-MMM-YYYY HH:mm a'), 'Invalid date')) { alert('date is not correct'); } else { alert('date is correct'); } It is working fine but the problem is if I provide

PHP date_format(): How to format date from string value

家住魔仙堡 提交于 2019-12-05 13:47:40
I have a bit of PHP code: $exd = date_create('01 Dec, 2015'); $exd = date_format($exd, 'Y-m-d'); echo $exd; Which is used for formatting the date. The expected output would be 2015-12-01 but it returns 2016-12-01 . What am i missing? Use createFromFormat method first, provide the input format: $exd = DateTime::createFromFormat('d M, Y', '01 Dec, 2015'); // arguments (<format of the input>, <the input itself>) $exd = date_format($exd, 'Y-m-d'); // then choose whatever format you like echo $exd; The date_create() function accepts only the parameter link , This function is also and alias function

Get exact day from date string in Javascript

﹥>﹥吖頭↗ 提交于 2019-12-05 13:07:05
I have checked this SO post: Where can I find documentation on formatting a date in JavaScript? Also I have looked into http://home.clara.net/shotover/datetest.htm My string is: Mon Jun 24 2013 05:30:00 GMT+0530 (India Standard Time) And I want to convert it to dd-mm-yyyy format. I tried using: var dateString = 'Mon Jun 24 2013 05:30:00 GMT+0530 (India Standard Time)'; var myDate = new Date(dateString); var final_date = myDate.getDay()+"-"+(myDate.getMonth()+1)+"-"+myDate.getFullYear(); But it gives me the result as: 1-6-2013 The getDay() value is the index of day in a week. For Instance, If

PostgreSQL - Create table and set specific date format

随声附和 提交于 2019-12-05 10:51:21
I want to create a new table and set a date type with a specific format. Is that possible? For example: CREATE TABLE User ( ... EXPIRATION DATE " YYYY/MM" ... ) Erwin Brandstetter I suggest a different approach: Never store date / time as character type ( text , varchar() , ...) to begin with. Use an appropriate type , probably date in your case. Also, never use reserved words as identifier. user is just not possible to begin with, you would have to double-quote, which I would discourage. Could look like this: CREATE TABLE usr ( usr_id serial PRIMARY KEY ,usr text UNIQUE ,expiration_date date

WPF DatePicker format

。_饼干妹妹 提交于 2019-12-05 09:13:18
I got this sample code from this forum. <DatePicker SelectedDate="{Binding myVideModelProperty}" Height="25" HorizontalAlignment="Left" Margin="81,-2,0,0" Name="myDatePicker" VerticalAlignment="Top" Width="115"> <DatePicker.Resources> <Style TargetType="{x:Type DatePickerTextBox}"> <Setter Property="Control.Template"> <Setter.Value> <ControlTemplate> <TextBox x:Name="PART_TextBox" Text="{Binding Path=SelectedDate, RelativeSource={RelativeSource AncestorType={x:Type DatePicker}}, StringFormat={}{0:yyyy/MM/dd}}" /> </ControlTemplate> </Setter.Value> </Setter> </Style> </DatePicker.Resources> <

SimpleDateFormat toPattern behaves differently in java 9

被刻印的时光 ゝ 提交于 2019-12-05 08:49:26
DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.SHORT, new Locale("SV", "SE")); ((SimpleDateFormat) dateFormat).toPattern(); In Java 8 this line produces "yyyy-MM-dd" while in Java 9 it produces "y-MM-dd" . This has some serious issues for our legacy code, is there some way to revert the behaviour? System.setProperty("java.locale.providers", "COMPAT,CLDR"); DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.SHORT, new Locale("sv", "SE")); System.out.println(((SimpleDateFormat) dateFormat).toPattern()); Running on my jdk-9.0.4 this prints yyyy-MM-dd You may want to set

Android - format Date to “Day, Month dd, yyyy”

好久不见. 提交于 2019-12-05 06:01:08
I get from the user, the date he sets in a DatePickerDialog. The date i get is in this format: int selectedYear, int selectedMonth, int selectedDay Can i format it to be like this "Day, Month dd, yyyy" as shown in the picture below? Using the values returned from picker int selectedYear = 2013; int selectedDay = 20; int selectedMonth = 11; Calendar cal = Calendar.getInstance(); cal.set(Calendar.YEAR, selectedYear); cal.set(Calendar.DAY_OF_MONTH, selectedDay); cal.set(Calendar.MONTH, selectedMonth); String format = new SimpleDateFormat("E, MMM d, yyyy").format(cal.getTime()); You can Try This:

Get date format like “Y-m-d H:i:s” from a php date

对着背影说爱祢 提交于 2019-12-05 03:24:40
Does someone know a way to get a string from a date that contains the format of the date? <?php $date = date ("2009-10-16 21:30:45"); // smething like this? print date_format ($date); ?> I ask this because I'd like to optimize this function I've written, usually to get the date with a different timezone from a server, without doing particular things <?php function get_timezone_offset ($timezone, $date = null, $format = null, $offset_timezone = null) { if ($date == null) $date = date ($format); if ($offset_timezone == null) $offset_timezone = date_default_timezone_get (); if ($format == null)