Displaying server time on client (shortened)

Hey!

I’m using this code to display server time

if (Meteor.isClient) {
    Meteor.startup(function () {
        setInterval(function () {
            Meteor.call("getServerTime", function (error, result) {
                Session.set("time", result);
            });
        }, 1000);
    });

    Template.main.time = function () {
        return Session.get("time");
    };
}

if (Meteor.isServer) {
    Meteor.methods({
        getServerTime: function () {
            var _time = (new Date).toTimeString();
            console.log(_time);
            return _time;
        }
    });
}

Now, the output is “17:22:18 GMT+0200 (CEST)”. How can i shorten that to only display for example 17:22?

Thanks in advance

  • Glutch
var _time = (new Date).toTimeString().substring(0,5);

Or you can have fun with regular expressions:

var _time = (new Date).toTimeString().replace(/:\d\d .*/, '');

ooh, awesome. Thank you a lot! :smile: