我如何添加“空间”输出而无需包装文本(react,typecript)

发布于 2025-01-25 11:12:03 字数 465 浏览 2 评论 0 原文

我想在我的表列中显示当前时间为“ HH:MM UHR”。 它可以很好地工作,直到我在HH:MM和“ UHR”一词之间的代码中添加一个空间。如果我这样做,文字将包装。 在我看来,空间字符可作为在代码中输入的功能。 有人对我有可能起作用的解决方案吗?

这是我的代码:

let currentTime = `${hours.toString().length === 1 ? `0${hours}` : hours}:${minutes.toString().length === 1 ? `0${minutes}` : minutes} Uhr`;

我的意思是最终的代码:分钟} uhr`;

如果我留出空间,输出:

09:33Uhr

如果我放置空间,则输出:

09:33
Uhr

I want to display the current time as "hh:mm Uhr" in my table column.
It works well until I add a space within the code between the hh:mm and the word 'Uhr'. If I do so, the text will wrap.
It seems to me that the space character functions as enter within the code.
Does anyone have a solution for me that might work?

Here is my code:

let currentTime = `${hours.toString().length === 1 ? `0${hours}` : hours}:${minutes.toString().length === 1 ? `0${minutes}` : minutes} Uhr`;

The piece of code I mean is in the end: minutes} Uhr`;

The output if I leave out space:

09:33Uhr

The output if I put space there:

09:33
Uhr

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

强辩 2025-02-01 11:12:03

您可以通过添加& nbsp; 尝试尝试,

以便您的代码为:
令CurrentTime = $ {houth.tostring()。长度=== 1? 0 $ {小时} :小时}:$ {分钟.tostring()。 ;

You can try by adding  

So your code will be:
let currentTime = ${hours.toString().length === 1 ? 0${hours}: hours}:${minutes.toString().length === 1 ?0${minutes} : minutes} Uhr;

老娘不死你永远是小三 2025-02-01 11:12:03

我通过不同的方法解决了问题。有一个名为dayjs的插件。它使使用时间并更轻松地进行编辑。

这是我的代码:

function processDate(date: string) {
    const parsedDate = dayjs(date).locale("de"); {/*Enter your country letters here to use your local time*/}
    return (
        <>
            <div>
                {parsedDate.format('DD MMM YYYY')}  {/Output: *01 Jan 1970*/}
            </div>
            <div>
                {parsedDate.format('HH:mm')} h {/Output: *00:00 h*/}
            </div>
            <div>
                {parsedDate.from(dayjs())} {/*takes the difference from then to now*/}
            </div>
        </>
    )
    /*format('DD MMM YYYY, HH:mm [h]');*/

您必须安装Dayjs才能使用它。
另外,还有一个很好的文档:
https://github.com/iamkun/ dayjs/blob/dev/docs/en/api-reference.md#显示

I solved the problem with a different approach. There is a plugin called dayjs. It makes using time and editing it a lot easier.

This is my code now:

function processDate(date: string) {
    const parsedDate = dayjs(date).locale("de"); {/*Enter your country letters here to use your local time*/}
    return (
        <>
            <div>
                {parsedDate.format('DD MMM YYYY')}  {/Output: *01 Jan 1970*/}
            </div>
            <div>
                {parsedDate.format('HH:mm')} h {/Output: *00:00 h*/}
            </div>
            <div>
                {parsedDate.from(dayjs())} {/*takes the difference from then to now*/}
            </div>
        </>
    )
    /*format('DD MMM YYYY, HH:mm [h]');*/

You have to install dayjs to use it.
Also, there is a nice documentation about it:
https://github.com/iamkun/dayjs/blob/dev/docs/en/API-reference.md#displaying

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文