如何使人性化器不显示毫秒? [英] How do I make humanizer not display milliseconds?

查看:75
本文介绍了如何使人性化器不显示毫秒?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何让Humanizer不显示毫秒?



i不希望我的结果中的最后几毫秒



我如何删除它?



有没有办法做到这一点或删除最后一毫秒部分



我正在使用 Humanizer GitHub Humanizer [ ^ ]将Timespan 转换为人类可读时间



见图像下方

[ ^ ]



如果有人知道这一点然后请帮助



谢谢



我尝试了什么:



i我这样做: -



How do i make Humanizer not display milliseconds?

i don't want that last milliseconds in my result

how do i remove this?

Is there any method to do that or to remove that last milliseconds part

I am using Humanizer GitHub Humanizer[^] to convert Timespan to human readable time

see below the image
[^]

if anyone know this then please help

thanks

What I have tried:

i am doing it like this :-

Console.WriteLine("Time Remaining :- {0}", timeRemaining.Humanize(5));

推荐答案

更好地写一个扩展方法 [ ^ ]删除毫秒/毫秒而不是重构整个库。



Better write an Extension Method[^] to remove the milliseconds/millisecond instead fo refactoring the entire library.

using System;
using Humanizer;
namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string a = TimeSpan.FromMilliseconds(1).Humanize().RemoveMilliSeconds();
        }
    }

    public static class HumanizerExtension
    {
        public static string RemoveMilliSeconds(this string s)
        {
           return s.Replace("millisecond", "").Replace("milliseconds", "");
        }
    }
}


你应该与创建它的人交谈 - 他们应该提供技术支持和意愿比我们更了解他们的产品。如果他们没有,那么找到另一个控件,并使用它!
You should talk to the people who created it - they should provide technical support and will know more about their product than we will. If they don't, then find another control, and use that!


你有没有想过阅读 GitHub - Humanizr / Humanizer:Humanizer满足您操作和显示字符串,枚举,日期,时间,时间跨度,数量和数量的所有.NET需求 [ ^ ]?
Did you think to read the documentation at GitHub - Humanizr/Humanizer: Humanizer meets all your .NET needs for manipulating and displaying strings, enums, dates, times, timespans, numbers and quantities[^]?


这篇关于如何使人性化器不显示毫秒?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆