Format Date on 2 Lines

Format date on 2 lines

Your code should work. Maybe it confuses you, that if you check the values of your return-values from within the playground for example, the value is like that:

"6:21PM\n19 May 2015"

But if I use your code like that:

public func smdt(date:NSDate)->NSString{
var dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "h:mma\ndd MMMM yyyy"
return dateFormatter.stringFromDate(date)
}

And call the value by using println:

println(smdt2(NSDate()))

The value printed out is like that:

6:22PM
19 May 2015

So you can use your code like you tried already.

But you also could split the hour and day/month like that and concate it later:

public func smdt(date:NSDate)->NSString{
var dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "h:mma"
var hour = dateFormatter.stringFromDate(date)
dateFormatter.dateFormat = "dd MMMM yyyy"

var otherPart = dateFormatter.stringFromDate(date)
return "\(hour)\n\(otherPart)"
}

How to format a date to be displayed in 2 lines?

Replace \n with <br/>
Also replace

Session["LastLoginDate"].ToString()

with

(DateTime)Session["LastLoginDate"]

React/Momentjs date formatting with line break

If you want to get Tholle's solution working with react-moment, you'll want to do the following:

<Moment style={{whiteSpace: "pre"}} format={"MMM[\n]d"}>{`${date}`}</Moment>

By putting your format within brackets, the [\n] will have the desired effect.

Splitting the date and time into two lines in javascript

Ciao, you could use split function by splitting date string in comma.
Something like:

moment().format('MMMM Do YYYY, h:mm:ss a').split(',')[0] // to see date
moment().format('MMMM Do YYYY, h:mm:ss a').split(',')[1] // to see time

Of course this is just an example. You could try to initialize a var with moment time formatted and the on td apply the split function.

EDIT

@RobG made an intersting observation on comment and I think is useful to add it to the answer. The way I suggested infact does not use all the library potentiality. Infact, moment provides the possibility to format date by inserting a br tag in format itself. So, you can do also in this (very efficient) way:

moment(item.pickup_date).format('MMMM Do YYYY[<br>]h:mm:ss a')

DateTime to string, formatting a line break into string while preserving culture

You can use Date and Time Format Strings to format a DateTime value in a custom way:

string result = string.Format("{0:d}\n{0:T}", timestamp);

// result == "6/15/2009\n1:45:30 PM" (en-US)
// result == "15.06.2009\n13:45:30" (de-DE)

Format date and time in a Windows batch script

I ended up with this script:

set hour=%time:~0,2%
if "%hour:~0,1%" == " " set hour=0%hour:~1,1%
echo hour=%hour%
set min=%time:~3,2%
if "%min:~0,1%" == " " set min=0%min:~1,1%
echo min=%min%
set secs=%time:~6,2%
if "%secs:~0,1%" == " " set secs=0%secs:~1,1%
echo secs=%secs%

set year=%date:~-4%
echo year=%year%

:: On WIN2008R2 e.g. I needed to make your 'set month=%date:~3,2%' like below ::otherwise 00 appears for MONTH

set month=%date:~4,2%
if "%month:~0,1%" == " " set month=0%month:~1,1%
echo month=%month%
set day=%date:~0,2%
if "%day:~0,1%" == " " set day=0%day:~1,1%
echo day=%day%

set datetimef=%year%%month%%day%_%hour%%min%%secs%

echo datetimef=%datetimef%

how to create new line between dateformat

I think Android literally needs \n to appear in the string, not an actual newline character. So, you need to escape the backslash in your Java string, so something like this:

String output = "Thus ,Sep 6" + "\\n" + "4:25pm";

Format date/time in line plot - matplotlib

Inspired by the answer above, I found a way to adjust the formatting as well as the frequency of x-ticks for a line plot when dealing with time series.

ax.xaxis.set_major_locator(md.HourLocator(interval=8))
ax.xaxis.set_major_formatter(
md.DateFormatter("%Y-%d-%m %H:%M")
)
ax.set_xlim(pd.Timestamp('2022-06-03 16:00:00'), pd.Timestamp('2022-06-06 10:00:00'))

For example the piece of code above helps you set how often you'd like your ticks to show up e.g. every 8 hour. The formatter used in this case will plot the date in short form (yyyy/mm/dd) and the hour and minute.



Related Topics



Leave a reply



Submit