JS一些常用的日期操作

福尔摩斯对我笑 2019-05-18 55211 次 8179条

日期格式化

Date.prototype.FormatDate = function(dt){
    if( !dt){
      dt = new Date();
    }
    var year = dt.getFullYear();
    var month = dt.getMonth() + 1;
    var day = dt.getDate();
    if (month <= 10) {
      month = '0' + month;
    }

    if (day <= 10) {
      day = '0' + day;
    }
    return year + '-' + month + '-' + day;
}

 

获取当前时间对应的前X个月份


Date.prototype.GetCurrentBeforeTime = function(num){
    num =  !num ? 12: num; 
    var result = [];
    var date = new Date( new Date().setMonth(new Date().getMonth() + 1) );
	for(let i=0; i< num; i++){
		date.setMonth( date.getMonth() - 1) 
		let m = date.getMonth() +1 
		m = m < 10 ? "0" + m : m;
		result.push( date.getFullYear() + "-" + m + "-"  + date.getDate())
    }

    return result;
}

获取当前时间对应的英文格式月份

Date.prototype.GetCurrentEnMonth = function(times){
    //没有参数时返回当前月份
    if(!times || !(times instanceof Array) ){
        return new Date().toDateString().split(" ")[1];
    }

    let monthStr = [];
    times.forEach(elem=>{
		let month = new Date(elem).toDateString().split(" ")[1];
		monthStr.push( month)
    })
    
    return monthStr;
}
标签:

非特殊说明,本博所有文章均为博主原创。

头像也是LOGO
未来博客 博主大人
到了这个年纪,不应该再彷徨!

发表评论



 


已有 8179 条评论 1


  1. dresser assembly service

    I precisely had to appreciate you again. I’m not certain what I might have followed without the actual recommendations discussed by you about that industry. Completely was a intimidating circumstance in my opinion, however , coming across this well-written manner you handled the issue forced me to weep with delight. Now i’m happy for the assistance and then wish you recognize what a great job that you’re undertaking training many others through the use of your blog. Probably you have never got to know any of us.

    回复 2019年12月10日
  2. Suitcases

    Also I believe that mesothelioma cancer is a extraordinary form of many forms of cancer that is commonly found in those people previously familiar with asbestos. Cancerous cells form in the mesothelium, which is a protecting lining which covers the vast majority of body’s areas. These cells commonly form in the lining on the lungs, tummy, or the sac that really encircles one’s heart. Thanks for giving your ideas.

    回复 2019年12月10日
  3. house cleaning Las Vegas

    Thanks for ones marvelous posting! I really enjoyed reading it, you may be a great author.I will make certain to bookmark your blog and may come back very soon. I want to encourage you to ultimately continue your great job, have a nice weekend!

    回复 2019年12月9日
  4. house cleaning Las Vegas

    Woah! I’m really loving the template/theme of this site. It’s simple, yet effective. A lot of times it’s hard to get that “perfect balance” between usability and visual appearance. I must say you have done a superb job with this. Also, the blog loads extremely quick for me on Internet explorer. Excellent Blog!

    回复 2019年12月9日
  5. เกมส์ ไฮโล ลูกเต๋า ฟรี

    Well I sincerely liked reading it. This information offered by you is very useful for proper planning.

    回复 2019年12月9日
  6. Furniture assembly help

    Great work! This is the type of info that should be shared around the internet. Shame on the search engines for not positioning this post higher! Come on over and visit my site . Thanks =)

    回复 2019年12月9日
  7. Pool table assembly service

    Hey there! Do you know if they make any plugins to safeguard against hackers? I’m kinda paranoid about losing everything I’ve worked hard on. Any recommendations?

    回复 2019年12月9日
  8. i99BET

    You have made some decent points there. I looked on the internet to find out more about the issue and found most individuals will go along with your views on this site.

    回复 2019年12月9日
  9. i99BET

    This website was… how do you say it? Relevant!! Finally I’ve found something which helped me. Appreciate it.

    回复 2019年12月9日
  10. Furniture assembly help

    In these days of austerity as well as relative stress and anxiety about taking on debt, some people balk against the idea of using a credit card in order to make purchase of merchandise or pay for any occasion, preferring, instead just to rely on the tried and also trusted procedure for making transaction – raw cash. However, if you have the cash on hand to make the purchase fully, then, paradoxically, that is the best time just to be able to use the card for several factors.

    回复 2019年12月8日
  11. Furniture installation

    You actually make it appear so easy with your presentation however I in finding this matter to be actually one thing that I believe I’d never understand. It sort of feels too complex and extremely large for me. I’m having a look ahead for your next submit, I will attempt to get the dangle of it!

    回复 2019年12月8日
  12. Tractor Workshop Manuals

    You made some decent points there. I looked on the net for that problem and located most individuals should go in conjunction with with the internet site.

    回复 2019年12月8日
  13. UFABET

    Everything is very open with a very clear explanation of the issues. It was really informative. Your site is extremely helpful. Thank you for sharing.

    回复 2019年12月7日
  14. metro installation

    Thanks , I’ve recently been looking for info about this topic for a while and yours is the best I have came upon till now. But, what in regards to the bottom line? Are you certain concerning the supply?

    回复 2019年12月7日
  15. Furniture assembly team

    Hi! Quick question that’s entirely off topic. Do you know how to make your site mobile friendly? My web site looks weird when viewing from my iphone. I’m trying to find a theme or plugin that might be able to fix this problem. If you have any recommendations, please share. Many thanks!

    回复 2019年12月7日
  16. ตู้ม้าออนไลน์ scr888

    Would you be eager about exchanging hyperlinks?

    回复 2019年12月6日
  17. 해외축구중계

    I have recently started a website, the information you provide on this website has helped me greatly. Thanks for all of your time & work.

    回复 2019年12月6日
  18. assemblers incorporated

    I went over this web site and I conceive you have a lot of fantastic info, saved to fav (:.

    回复 2019年12月6日
  19. logo

    You can definitely see your enthusiasm in the work you write. The arena hopes for more passionate writers like you who aren’t afraid to say how they believe. All the time go after your heart.

    回复 2019年12月6日
  20. udaipur escorts

    Do you mind if I quote a couple of your posts as long as I provide credit and sources back to your weblog? My blog site is in the exact same area of interest as yours and my visitors would certainly benefit from some of the information you provide here. Please let me know if this alright with you. Thanks!

    回复 2019年12月6日
  21. togel online

    Hmm is anyone else experiencing problems with the pictures on this blog loading? I’m trying to determine if its a problem on my end or if it’s the blog. Any responses would be greatly appreciated.

    回复 2019年12月5日
  22. i99bet

    After going over a handful of the blog articles on your web site, I seriously appreciate your way of blogging. I saved it to my bookmark webpage list and will be checking back soon. Please check out my website as well and let me know what you think.

    回复 2019年12月4日
  23. John Deere Repair Manuals

    There are some interesting deadlines on this article but I don’t know if I see all of them middle to heart. There is some validity but I’ll take maintain opinion till I look into it further. Good article , thanks and we wish extra! Added to FeedBurner as well

    回复 2019年12月3日
  24. i99bet

    I really like it when folks get together and share thoughts. Great website, continue the good work!

    回复 2019年12月3日
  25. Pozycjonowanie Cennika Gorzow Wielkopolski

    I like what you guys are up too. Such smart work and reporting! Keep up the excellent works guys I have incorporated you guys to my blogroll. I think it’ll improve the value of my website :).

    回复 2019年11月30日
  26. Hulda Wela

    I need yet to really understand together with comprehend that essence in the contents from your article

    回复 2019年11月29日
  27. Demarcus Delley

    I am not sure where you’re getting your information, but great topic. I needs to spend some time learning much more or understanding more. Thanks for great info I was looking for this information for my mission.

    回复 2019年11月28日
  28. view publisher site

    I just want to say I’m beginner to blogging and truly loved you’re web page. More than likely I’m likely to bookmark your site . You amazingly have incredible writings. Cheers for sharing with us your web page.

    回复 2019年11月24日
  29. StevDede

    Cialis Effetti Indesiderati viagra online pharmacy Propecia Espalnds Bueno

    回复 2019年11月5日